Skip to content

Commit 67f53ff

Browse files
committed
Add tests for main export
1 parent 77bf87f commit 67f53ff

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var proxyquire = require( 'proxyquire' );
25+
var builtin = require( './../lib/builtin.js' );
26+
var wrapper = require( './../lib/builtin_wrapper.js' );
27+
var polyfill = require( './../lib/polyfill.js' );
28+
var objectKeys = require( './../lib/main.js' );
29+
30+
31+
// TESTS //
32+
33+
tape( 'main export is a function', function test( t ) {
34+
t.ok( true, __filename );
35+
t.strictEqual( typeof objectKeys, 'function', 'main export is a function' );
36+
t.end();
37+
});
38+
39+
tape( 'if an environment has a non-buggy built-in implementation, the export is the built-in implementation', function test( t ) {
40+
var objectKeys = proxyquire( './../lib/main.js', {
41+
'./has_builtin.js': true,
42+
'./has_arguments_bug.js': mock
43+
});
44+
t.strictEqual( objectKeys, builtin, 'is expected value' );
45+
t.end();
46+
47+
function mock() {
48+
return false;
49+
}
50+
});
51+
52+
tape( 'if an environment has a buggy built-in implementation (i.e., does not support `arguments`, as in Safari 5.0), the export is a wrapper which patches the built-in implementation', function test( t ) {
53+
var objectKeys = proxyquire( './../lib/main.js', {
54+
'./has_builtin.js': true,
55+
'./has_arguments_bug.js': mock
56+
});
57+
t.strictEqual( objectKeys, wrapper, 'is expected value' );
58+
t.end();
59+
60+
function mock() {
61+
return true;
62+
}
63+
});
64+
65+
tape( 'if an environment does not have a built-in implementation, the export is a polyfill', function test( t ) {
66+
var objectKeys = proxyquire( './../lib/main.js', {
67+
'./has_builtin.js': false
68+
});
69+
t.strictEqual( objectKeys, polyfill, 'is expected value' );
70+
t.end();
71+
});

0 commit comments

Comments
 (0)