forked from airbnb/react-with-styles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw appropriate errors for invalid instantiation.
Throw appropriate errors if a Style Interface has not been registered or an invalid Style Interface has been registered. Throw an appropriate error if a Theme has not been registered. Resolves: airbnb#102
- Loading branch information
1 parent
e17dea5
commit dc0011d
Showing
2 changed files
with
102 additions
and
0 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
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,57 @@ | ||
import { expect } from 'chai'; | ||
import globalCache from 'global-cache'; | ||
|
||
let ThemedStyleSheet; | ||
|
||
describe('ThemedStyleSheet', () => { | ||
beforeEach(() => { | ||
ThemedStyleSheet = require('../src/ThemedStyleSheet').default; // eslint-disable-line global-require | ||
}); | ||
|
||
afterEach(() => { | ||
delete require.cache[require.resolve('../src/ThemedStyleSheet')]; | ||
globalCache.clear(); | ||
}); | ||
|
||
describe('errors', () => { | ||
it('throws a Reference Error if a theme has not been registered and create is called', () => { | ||
ThemedStyleSheet.registerInterface({ | ||
create() {}, | ||
resolve() {}, | ||
}); | ||
expect(ThemedStyleSheet.create).to.throw(ReferenceError); | ||
}); | ||
|
||
describe('Style Interface', () => { | ||
beforeEach(() => { | ||
ThemedStyleSheet.registerTheme({}); | ||
}); | ||
|
||
it('throws a ReferenceError if an interface has not be registered and create is called', () => { | ||
expect(ThemedStyleSheet.create).to.throw(ReferenceError); | ||
}); | ||
|
||
it('throws a ReferenceError if an interface has not be registered and resolve is called', () => { | ||
expect(ThemedStyleSheet.resolve).to.throw(ReferenceError); | ||
}); | ||
|
||
it('throws a TypeError if create is not a function when the interface is registered', () => { | ||
const mockInterface = { | ||
create: {}, | ||
resolve() {}, | ||
}; | ||
const register = () => ThemedStyleSheet.registerInterface(mockInterface); | ||
expect(register).to.throw(TypeError); | ||
}); | ||
|
||
it('throws a TypeError if resolve is not a function when the interface is registered', () => { | ||
const mockInterface = { | ||
create() {}, | ||
resolve: {}, | ||
}; | ||
const register = () => ThemedStyleSheet.registerInterface(mockInterface); | ||
expect(register).to.throw(TypeError); | ||
}); | ||
}); | ||
}); | ||
}); |