forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
199 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,6 @@ | |
"dependencies": { | ||
"graphql": "file:../graphql.tgz", | ||
"graphql-esm": "file:../graphql-esm.tgz", | ||
"typescript-4.4": "npm:[email protected]", | ||
"typescript-4.5": "npm:[email protected]", | ||
"typescript-4.6": "npm:[email protected]", | ||
"typescript-4.7": "npm:[email protected]", | ||
"typescript-4.8": "npm:[email protected]", | ||
"typescript-4.9": "npm:[email protected]", | ||
"typescript-5.0": "npm:[email protected]", | ||
"typescript-5.1": "npm:[email protected]", | ||
"typescript-5.2": "npm:[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import { instanceOf as instanceOfForDevelopment } from '../instanceOfForDevelopment.ts'; | ||
|
||
describe('instanceOfForDevelopment', () => { | ||
it('do not throw on values without prototype', () => { | ||
class Foo { | ||
get [Symbol.toStringTag]() { | ||
return 'Foo'; | ||
} | ||
} | ||
|
||
expect(instanceOfForDevelopment(true, Foo)).to.equal(false); | ||
expect(instanceOfForDevelopment(null, Foo)).to.equal(false); | ||
expect(instanceOfForDevelopment(Object.create(null), Foo)).to.equal(false); | ||
}); | ||
|
||
it('detect name clashes with older versions of this lib', () => { | ||
function oldVersion() { | ||
class Foo {} | ||
return Foo; | ||
} | ||
|
||
function newVersion() { | ||
class Foo { | ||
get [Symbol.toStringTag]() { | ||
return 'Foo'; | ||
} | ||
} | ||
return Foo; | ||
} | ||
|
||
const NewClass = newVersion(); | ||
const OldClass = oldVersion(); | ||
expect(instanceOfForDevelopment(new NewClass(), NewClass)).to.equal(true); | ||
expect(() => instanceOfForDevelopment(new OldClass(), NewClass)).to.throw(); | ||
}); | ||
|
||
it('allows instances to have share the same constructor name', () => { | ||
function getMinifiedClass(tag: string) { | ||
class SomeNameAfterMinification { | ||
get [Symbol.toStringTag]() { | ||
return tag; | ||
} | ||
} | ||
return SomeNameAfterMinification; | ||
} | ||
|
||
const Foo = getMinifiedClass('Foo'); | ||
const Bar = getMinifiedClass('Bar'); | ||
expect(instanceOfForDevelopment(new Foo(), Bar)).to.equal(false); | ||
expect(instanceOfForDevelopment(new Bar(), Foo)).to.equal(false); | ||
|
||
const DuplicateOfFoo = getMinifiedClass('Foo'); | ||
expect(() => | ||
instanceOfForDevelopment(new DuplicateOfFoo(), Foo), | ||
).to.throw(); | ||
expect(() => | ||
instanceOfForDevelopment(new Foo(), DuplicateOfFoo), | ||
).to.throw(); | ||
}); | ||
|
||
it('fails with descriptive error message', () => { | ||
function getFoo() { | ||
class Foo { | ||
get [Symbol.toStringTag]() { | ||
return 'Foo'; | ||
} | ||
} | ||
return Foo; | ||
} | ||
const Foo1 = getFoo(); | ||
const Foo2 = getFoo(); | ||
|
||
expect(() => instanceOfForDevelopment(new Foo1(), Foo2)).to.throw( | ||
/^Cannot use Foo "{}" from another module or realm./m, | ||
); | ||
expect(() => instanceOfForDevelopment(new Foo2(), Foo1)).to.throw( | ||
/^Cannot use Foo "{}" from another module or realm./m, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.