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
/* @flow */ | |
function foo(x: ?number): string { | |
if (x) { | |
return x; | |
} | |
return "default string"; | |
} |
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
import * as React from "react"; | |
import ReactDOM from "react-dom"; | |
import { Input } from "../"; | |
test("it initializes with a defaultValue", () => { | |
const defaultValue = "DefaultValue"; | |
const wrapper = mount(<Input initialValue={defaultValue} />); | |
const input = wrapper.find("input"); | |
expect(input.instance().value).toBe(defaultValue); |
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
import React from 'react'; | |
import Link from '../Link.react'; | |
import renderer from 'react-test-renderer'; | |
it('renders correctly', () => { | |
const tree = renderer | |
.create(<Link page="http://www.facebook.com">Facebook</Link>) | |
.toJSON(); | |
expect(tree).toMatchSnapshot(); | |
}); |
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
it('renders correctly', () => { | |
const tree = renderer | |
.create(<Link page="https://prettier.io">Prettier</Link>) | |
.toJSON(); | |
expect(tree).toMatchInlineSnapshot(); | |
}); | |
// Will be changed after one Jest run into: | |
it('renders correctly', () => { |
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
it('will check the matchers and pass', () => { | |
const user = { | |
createdAt: new Date(), | |
id: Math.floor(Math.random() * 20), | |
name: 'LeBron James', | |
}; | |
expect(user).toMatchSnapshot({ | |
createdAt: expect.any(Date), | |
id: expect.any(Number), |
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
// src/__mocks_axios.js | |
const mockAxios = jest.genMockFromModule('axios') | |
// this is the key to fix the axios.create() undefined error! | |
mockAxios.create = jest.fn(() => mockAxios) | |
export default mockAxios | |
// example test class which uses axios mock |
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
import { useEffect, useReducer } from "react"; | |
export interface QueryArgs<T> { | |
url: string; | |
options: RequestInit; | |
deserialize?: (res: Response) => Promise<T>; | |
} | |
export interface QueryAction<T> { | |
type: string; |
OlderNewer