tests_with_jasmine
npm init
a new application. Enter, enter, enter...tree
. Now, add an app
and a spec
folder.npm install jasmine-node --save-dev
node_modules/.bin/jasmine-node spec
node_modules/.bin/jasmine-node spec
describe('a set of problems to solve', function() {
describe('a failing test', function() {
it('fails', function() {
//expect(false).toBe(true);
});
});
describe('an individual problem to solve', function() {
it('a basic test', function() {
var expected = 'solution';
//var assert = 'womp womp';
var assert = expected;
expect(assert).toBe(expected);
});
});
});
describe('to be? or not to be?', function() {
it('it wants to be, therefore it is...', function() {
var expected = 'I exist! Therefore, I am';
var assert = expected;
expect(assert).toEqual(expected);
});
it('it does not want to be, therefore it is not...', function() {
var expected = undefined;
var assert;
expect(assert).toEqual(expected);
});
});
Provide the following tests to the students and have them solve them.
describe('make sure math is really universal', function() {
it('should add numbers together', function() {
var expected = 42;
expect(assert).toBe(expected);
});
it('should negate a number from another', function() {
var expected = 20;
expect(assert).toBe(expected);
});
it('should multiple two numbers together', function() {
var expected = 49;
expect(assert).toBe(expected);
});
it('should divide a number by another number', function() {
var expected = 7;
expect(assert).toBe(expected);
});
it('should correctly return a remainder', function() {
var expected = 1;
// use modulus aka %
expect(assert).toBe(expected);
});
});
expect(fn).toThrow(e);
expect(instance).toBe(instance);
expect(mixed).toBeDefined();
expect(mixed).toBeFalsy();
expect(number).toBeGreaterThan(number);
expect(number).toBeLessThan(number);
expect(mixed).toBeNull();
expect(mixed).toBeTruthy();
expect(mixed).toBeUndefined();
expect(array).toContain(member);
expect(string).toContain(substring);
expect(mixed).toEqual(mixed);
expect(mixed).toMatch(pattern);