Files
lodash/test/isWeakMap.test.js
Benjamin Tan d5ef31929a Add initial test files from lodash v4. (#4172)
* Install test dependencies.

* Add initial test files.

These files were created using a simplistic AST manipulator using `recast` to
preserve formatting. There's bound to be a huge chunk of errors, but this serves
as a good start. QUnit was replaced with Mocha, with ES2015 imports running via
`esm`.

As far as possible, QUnit-specific syntax has been replaced with Mocha's
`describe` and `it`, while the native Node.js `assert` module is used for
assertions. Files in the `test` directory ending in `.test.js` will be treated
as test files.

* Add initial passing files to test run.
2019-02-12 09:11:32 -08:00

54 lines
1.8 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { weakMap, falsey, stubFalse, args, slice, map, symbol, realm } from './utils.js';
import isWeakMap from '../isWeakMap.js';
describe('isWeakMap', function() {
it('should return `true` for weak maps', function() {
if (WeakMap) {
assert.strictEqual(isWeakMap(weakMap), true);
}
});
it('should return `false` for non weak maps', function() {
var expected = lodashStable.map(falsey, stubFalse);
var actual = lodashStable.map(falsey, function(value, index) {
return index ? isWeakMap(value) : isWeakMap();
});
assert.deepStrictEqual(actual, expected);
assert.strictEqual(isWeakMap(args), false);
assert.strictEqual(isWeakMap([1, 2, 3]), false);
assert.strictEqual(isWeakMap(true), false);
assert.strictEqual(isWeakMap(new Date), false);
assert.strictEqual(isWeakMap(new Error), false);
assert.strictEqual(isWeakMap(_), false);
assert.strictEqual(isWeakMap(slice), false);
assert.strictEqual(isWeakMap({ 'a': 1 }), false);
assert.strictEqual(isWeakMap(map), false);
assert.strictEqual(isWeakMap(1), false);
assert.strictEqual(isWeakMap(/x/), false);
assert.strictEqual(isWeakMap('a'), false);
assert.strictEqual(isWeakMap(symbol), false);
});
it('should work for objects with a non-function `constructor` (test in IE 11)', function() {
var values = [false, true],
expected = lodashStable.map(values, stubFalse);
var actual = lodashStable.map(values, function(value) {
return isWeakMap({ 'constructor': value });
});
assert.deepStrictEqual(actual, expected);
});
it('should work with weak maps from another realm', function() {
if (realm.weakMap) {
assert.strictEqual(isWeakMap(realm.weakMap), true);
}
});
});