Skip to content

Commit ca4eb4b

Browse files
committed
Add tests for detecting whether an environment erroneously considers a prototype enumerable
1 parent 1907b1e commit ca4eb4b

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 isEnumerableProperty = require( '@stdlib/assert/is-enumerable-property' );
26+
var bool = require( './../lib/has_enumerable_prototype_bug.js' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a boolean', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof bool, 'boolean', 'main export is a boolean' );
34+
t.end();
35+
});
36+
37+
tape( 'the exported value is `true` if an environment treats a value\'s prototype as enumerable', function test( t ) {
38+
var bool = proxyquire( './../lib/has_enumerable_prototype_bug.js', {
39+
'@stdlib/assert/is-enumerable-property': mock
40+
});
41+
42+
t.strictEqual( bool, true, 'returns expected value' );
43+
t.end();
44+
45+
function mock( obj, prop ) {
46+
if ( prop === 'prototype' ) {
47+
return true;
48+
}
49+
return isEnumerableProperty( obj, prop );
50+
}
51+
});
52+
53+
tape( 'the exported value is `false` if an environment does not treat a value\'s prototype as enumerable', function test( t ) {
54+
var bool = proxyquire( './../lib/has_enumerable_prototype_bug.js', {
55+
'@stdlib/assert/is-enumerable-property': mock
56+
});
57+
58+
t.strictEqual( bool, false, 'returns expected value' );
59+
t.end();
60+
61+
function mock( obj, prop ) {
62+
if ( prop === 'prototype' ) {
63+
return false;
64+
}
65+
return isEnumerableProperty( obj, prop );
66+
}
67+
});

0 commit comments

Comments
 (0)