Skip to content

Commit

Permalink
feat: unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoHai committed Mar 18, 2019
1 parent 64028dc commit 6df6d74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/test-hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, act } from 'react-testing-library'
import { render, act, cleanup } from 'react-testing-library'

export default function testHooks<T>(wrapper: () => T) {
let hooks: T;
Expand All @@ -20,6 +20,9 @@ export default function testHooks<T>(wrapper: () => T) {
},
hooks() {
return hooks;
},
unmount() {
return cleanup();
}
}
}
3 changes: 2 additions & 1 deletion test/test-hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { useState } from 'react';

describe('test-hooks', () => {
it('basic usage', () => {
const { act, hooks } = testHooks(() => useState(true));
const { act, hooks, unmount } = testHooks(() => useState(true));
expect(hooks()[0]).toEqual(true);
act(hook => {
hook[1](false);
});
expect(hooks()[0]).toEqual(false);
unmount();
});
});

0 comments on commit 6df6d74

Please sign in to comment.