- Notifications
You must be signed in to change notification settings - Fork0
Mocha test runner & reporter for CodeRoad
coderoad/mocha-coderoad-deprecated
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Atom-CodeRoad Javascript test runner & reporter.
npm install mocha-coderoad
Useatom-snippets to quickly generate test files.
Open upAtom ->Open Your Snippets. Add the contents ofmocha-coderoadsnippets.cson
to your globalsnippets.cson
file.
Quickly generate tests using the following snippet prefixes:
- mochacr-f - test a function
- mochacr-a - test an array
- mochacr-o - test an object
It makes sense to write test statements using 'should', 'must' or negative statements. Remember, the failing test message will be delivered as feedback to the user.
it('should be a function')it('must be a function')it('isn\'t a function')
Use aloader to run the user saved file in the context of your file. Think of a loader as a way to place the file your testing inside of your test file. Loaders are written inside of comments.
// load('user-file.js');/* workspaceDirectory/user-file.js */
When loading files within your tutorial directory, add a second parameter oftrue
. This can allow you to low additional data variables or functions, for example:var data = {...}
.
// load('data-file.js', true)/* workspaceDirectory/node_modules/tutorial-name/tutorial/data-file.js */
Here are examples usingmocha withchai'sexpect. See thedocs.
it('doesn\'t exist',function(){expect(target).to.not.be.undefined;});
it('should be a function',function(){expect(target).to.be.a('function');});
it('should have two parameters',function(){expect(target).to.have.length(2);});
it('should add one to the number',function(){expect(addOne(1)).to.equal(2);});
it('should be 42',function(){expect(target).to.equal(42);});
it('should be {a: 42}',function(){expect(target).to.deep.equal({a:42});});
it('should include the variable "count"',function(){varregex=newRegExp('count');varstring=target.toString();expect(string.match(regex)).to.be.true;});
it('should access the property "prop"',function(){varregex1=/\.prop/;// dot notationvarregex2=/\[["']prop["']\]/;// bracket notationvarstring=target.toString();varresult=!!string.match(regex1)||!!string.match(regex2);expect(result).to.be.true;});
You can usesinon orchai-spies to create a spy. See an example below:
> npm i -s chai-spies
varchai=require('chai'),spies=require('chai-spies');varexpect=chai.expect;chai.use(spies);varspy=chai.spy.on(console,'log');loadJS('04-forEach.js');it('should write "hello world" to the console',function(){expect(spy).to.have.been.called.with('hello world');});
There are situations where you might want to change data based on the current task. In this case, be careful, as all earlier tests must continue to pass.
Some variables are passed into the test runner through the node environmentprocess.env.
See an example of dynamic data based on the task position below:
vardata=[1,2,3];if(process.env.TASK_POSITION==='4'){data=[1,2,3,4];}
Tests can also change based on the task position.
if(process.env.TASK_POSITION!=='4'){it('should do this',function(){ ...});}else{it('should to that',function(){ ...});}
See a fullexample.
It's entirely possible to create a simplified testing tool that could make writing tests faster & easier.
The easiest solution would be to use editor snippets to generate a page of tests from a simple configuration object. This does not yet exist.
CodeRoad tutorial configurations can be set in thepackage.json config.
{"config": {"testDir":"tutorial","testSuffix":".spec.js","testRunner":"mocha-coderoad","edit":true }}
This section will likely expand in the future. For now, let's go over some of the configurations.
The relative path to the unit test directory. This makes writing unit tests paths easier.
The common suffix for unit tests. Also making writing unit test paths shorter.
Specified test runner. Currently only "mocha-coderoad" is available.
If set to true,Atom-CodeRoad will allow users to submit issues or submit markdown pull requests. You will also need to specify "repository" & "bugs" in yourpackage.json file. See anexample config file.
About
Mocha test runner & reporter for CodeRoad
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.