Skip to content

Commit fff4339

Browse files
instanceOf: add additional tests (#3189)
1 parent 829acf0 commit fff4339

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/jsutils/__tests__/instanceOf-test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@ import { describe, it } from 'mocha';
44
import { instanceOf } from '../instanceOf';
55

66
describe('instanceOf', () => {
7+
it('do not throw on values without prototype', () => {
8+
class Foo {
9+
// $FlowFixMe[unsupported-syntax]
10+
get [Symbol.toStringTag]() {
11+
return 'Foo';
12+
}
13+
}
14+
15+
expect(instanceOf(true, Foo)).to.equal(false);
16+
expect(instanceOf(null, Foo)).to.equal(false);
17+
expect(instanceOf(Object.create(null), Foo)).to.equal(false);
18+
});
19+
20+
it('detect name clashes with older versions of this lib', () => {
21+
function oldVersion() {
22+
class Foo {}
23+
return Foo;
24+
}
25+
26+
function newVersion() {
27+
class Foo {
28+
// $FlowFixMe[unsupported-syntax]
29+
get [Symbol.toStringTag]() {
30+
return 'Foo';
31+
}
32+
}
33+
return Foo;
34+
}
35+
36+
const NewClass = newVersion();
37+
const OldClass = oldVersion();
38+
expect(instanceOf(new NewClass(), NewClass)).to.equal(true);
39+
expect(() => instanceOf(new OldClass(), NewClass)).to.throw();
40+
});
41+
742
it('allows instances to have share the same constructor name', () => {
843
function getMinifiedClass(tag: string) {
944
class SomeNameAfterMinification {

0 commit comments

Comments
 (0)