-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
6 changed files
with
115 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,22 @@ | ||
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun> | ||
// TypeScript Version: 2.4 | ||
|
||
/// <reference types="jest" /> | ||
import { Emotion } from 'create-emotion'; | ||
|
||
export interface CreateSerializerOptions { | ||
classNameReplacer?: (className: string, index: number) => string; | ||
DOMElements?: boolean; | ||
} | ||
|
||
export function getStyles(emotion: Emotion): string; | ||
export function createSerializer(emotion: Emotion, options?: CreateSerializerOptions): jest.SnapshotSerializerPlugin; | ||
export function createMatchers(emotion: Emotion): jest.ExpectExtendMap; | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toHaveStyleRule(property: string, value: any): R; | ||
} | ||
} | ||
} |
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,52 @@ | ||
/// <reference types="jest" /> | ||
import * as emotion from 'emotion'; | ||
import { | ||
CreateSerializerOptions, | ||
createSerializer, | ||
createMatchers, | ||
getStyles, | ||
} from '../'; | ||
|
||
createSerializer(emotion); | ||
createSerializer(emotion, {}); | ||
createSerializer(emotion, { | ||
DOMElements: true, | ||
}); | ||
createSerializer(emotion, { | ||
classNameReplacer() { | ||
return 'abc'; | ||
}, | ||
}); | ||
createSerializer(emotion, { | ||
classNameReplacer(className) { | ||
return className; | ||
}, | ||
}); | ||
createSerializer(emotion, { | ||
classNameReplacer(className, index) { | ||
return `${className}-${index}`; | ||
}, | ||
}); | ||
createSerializer(emotion, 213 as any as CreateSerializerOptions); | ||
// $ExpectError | ||
createSerializer(); | ||
// $ExpectError | ||
createSerializer(emotion, 1); | ||
// $ExpectError | ||
createSerializer(emotion, true); | ||
// $ExpectError | ||
createSerializer(emotion, {}, undefined as any); | ||
|
||
// $ExpectError | ||
createMatchers(); | ||
// $ExpectError | ||
createMatchers(emotion, undefined as any); | ||
|
||
expect.addSnapshotSerializer(createSerializer(emotion)); | ||
expect.extend(createMatchers(emotion)); | ||
|
||
expect({}).toHaveStyleRule('width', 'black'); | ||
expect({}).toHaveStyleRule('height', /red/); | ||
expect({}).toHaveStyleRule('color', expect.stringContaining('20')); | ||
// $ExpectError | ||
expect({}).toHaveStyleRule(5, 'abc'); |
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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "../", | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react", | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"module": "commonjs", | ||
"noEmit": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"target": "es5", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [] | ||
}, | ||
"include": [ | ||
"./*.ts", | ||
"./*.tsx" | ||
] | ||
} |
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,6 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"no-relative-import-in-test": false | ||
} | ||
} |
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
Shouldn't the
types/
directory get added here?