This tiny, time-saving tool, converts lines of human text into syntax understood by the Jest JavaScript testing framework.
Obviously it doesn't write your tests for you, but it does enable you to put the structure quickly into place so you can concentrate more on the task at hand.
Type in the name of a single test.
text2jest will wrap this name into a Jest test()
function for you.
display the username
test('display the username', () => { // });
You can add as many tests as you like.
display the usernamedisplay the email address
test('display the username', () => { // }); test('display the email address', () => { // });
Indent lines with one or more spaces under one another to create a hierarchy. When text2jest sees this nesting, the parent line becomes a describe()
.
You can nest as many levels deep as you like.
the UserInfo componentdisplay the usernamedisplay the email address
describe('the UserInfo component', () => { test('display the username', () => { // }); test('display the email address', () => { // }); });
You can add flags to any describe()
.
Add any combination of the flags listed below, and text2jest will prefill your setup and teardown methods.
The available flags are:
the UserInfo component *ba *aadisplay the usernamedisplay the email address
describe('the UserInfo component', () => { beforeAll(() => { // }); afterAll(() => { // }); test('display the username', () => { // }); test('display the email address', () => { // }); });
When writing a test()
, you can add an *as
flag to insert the async
keyword.
the UserInfo component *ba *aadisplay the username *asdisplay the email address *as
describe('the UserInfo component', () => { beforeAll(() => { // }); afterAll(() => { // }); test('display the username', async () => { // }); test('display the email address', async () => { // }); });
If you want to add a hyphen before each test name (ala Markdown bullet points) to make it easier to read, you can do that too.
- the UserInfo component- display the username- display the email address
describe('the UserInfo component', () => { test('display the username', () => { // }); test('display the email address', () => { // }); });
If you want to text2jest to ignore a line, add a javascript comment at the very start of the line.
- the UserInfo component// - display the username// - display the email address
test('the UserInfo component', () => { // });
If you prefer to use the alias it()
instead of test()
for the function name, you can specify this in the settings.
- the UserInfo component- displays the username- displays the email address
it('displays the username', () => { // }); it('displays the email address', () => { // });