Multiple tests per file?

167 views
Skip to first unread message

Joshua Gough

unread,
Oct 7, 2014, 4:49:22 PM10/7/14
to jes...@googlegroups.com
Hello!

I'm new to using Jest, and wanted to see if we're using it correctly so far.


We have this test file with one function under test, and two scenarios:


In case that link changes, here's the code:

describe('gitHubEventsToApiResponse', () => {
describe('when 0 events present', () => {
it('returns an empty array', () => {
expect(gitHubEventsToApiResponse([])).toEqual({
commits: []
});
});
});

describe('when 1 event present', () => {
let events = eventsData.Single;
let actual = gitHubEventsToApiResponse(events);
it('returns a 1 mapped event', () => {
expect(actual.commits.length).toEqual(1);
});
});
});

We run this first through traceur like this to convert from es6 to es5 (Didn't have luck with the native approach for Jest)

#!/usr/bin/sh
export PATH=$(pwd)/node_modules/.bin:$PATH

# Compile code from ES6 to ES5 before test
find . -name '__tests__' ! -path './node_modules/*' | xargs rm -rf
find . -name '__tests' ! -path './node_modules/*' -exec sh -c 'mkdir -p $1__ && traceur --modules commonjs --dir $1 $1__/ ' - {} \;

npm test


That's all fine so far, but when we see the output we get:

> openAgile.C...@0.0.1 test c:\Projects\github\CommitStream.Web\src\app
> jest

Found 1 matching test...
 PASS  api\translators\__tests__\gitHubEventsToApiResponse-test.js (0.071s)
1 test passed (1 total)
Run time: 3.027s


We were hoping it said, at least, 2 tests since we have 2 nested describe, or perhaps because of 2 it calls. Of course, it's all debatable how it should look.

But, I'm just curious is this something that's configurable or desirable if we wanted to contribute a pull-request?

Ben Alpert

unread,
Oct 7, 2014, 4:50:22 PM10/7/14
to Joshua Gough, jes...@googlegroups.com
Not currently configurable, but it'd be nice if it were:


--
You received this message because you are subscribed to the Google Groups "Jest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jestjs+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jestjs/584dbe18-be3e-40e2-8409-7e2ef342d588%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages