Fix broken tests

This commit is contained in:
Jerko Steiner 2019-09-01 15:40:34 +07:00
parent 5b5adb6408
commit 6a456eb6e8
4 changed files with 17 additions and 11 deletions

View File

@ -41,6 +41,7 @@ export class TeamManager extends React.PureComponent<ITeamManagerProps> {
const action = this.props.createTeam(team)
action.payload
.then(() => this.props.history.push('/teams'))
.catch(() => {/* do nothing */})
return action
}
render() {

View File

@ -31,10 +31,14 @@ export class TestUtils {
readonly createStore = createStore
render(jsx: JSX.Element) {
const component = T
.renderIntoDocument(jsx) as unknown as React.Component<any>
const node = ReactDOM.findDOMNode(component) as Element
return {component, node}
const $div = document.createElement('div')
const component = ReactDOM.render(
<div>{jsx}</div>, $div) as unknown as React.Component<any>
const node = (ReactDOM.findDOMNode(component) as Element).children[0]
return {
component,
node,
}
}
combineReducers<S>(reducers: ReducersMapObject<S, any>): Reducer<S>

View File

@ -26,8 +26,8 @@ export class Subprocess {
})
if (this.stdio === StdioOptions.PIPE) {
subprocess.stdout.on('data', data => process.stdout.write(data))
subprocess.stderr.on('data', data => process.stderr.write(data))
subprocess.stdout!.on('data', data => process.stdout.write(data))
subprocess.stderr!.on('data', data => process.stderr.write(data))
}
subprocess.on('close', code => {

View File

@ -10,9 +10,10 @@ describe('update', () => {
const stringify = (obj: object) => JSON.stringify(obj, null, ' ')
const readMock = fs.readFileSync as jest.Mock<typeof fs.readFileSync>
const readMock =
fs.readFileSync as unknown as jest.Mock<typeof fs.readFileSync>
const writeMock = fs.writeFileSync as jest.Mock<typeof fs.writeFileSync>
const cpMock = cp.execFileSync as jest.Mock<typeof cp.execFileSync>
const cpMock = cp.execFileSync as unknown as jest.Mock<typeof cp.execFileSync>
let outdated: Record<string, IOutdated> = {}
beforeEach(() => {
@ -35,17 +36,17 @@ describe('update', () => {
devDependencies: {
b: '^3.4.6',
},
}))
}) as any)
})
it('does not change when no changes', async () => {
cpMock.mockReturnValue('{}')
cpMock.mockReturnValue('{}' as any)
await update('update', '/my/dir')
expect(writeMock.mock.calls.length).toBe(0)
})
it('does not change when npm outdated output is empty', async () => {
cpMock.mockReturnValue('')
cpMock.mockReturnValue('' as any)
await update('update', '/my/dir')
expect(writeMock.mock.calls.length).toBe(0)
})