The document discusses testing and development environments and tools. It covers topics like unit testing frameworks, test runners, dependency management with package managers, bundling code with webpack, and using tasks runners like Gulp. It provides examples of using these tools like writing unit tests with Jasmine/Mocha, configuring webpack, and defining Gulp tasks.
21. describe('math test', function () {
it('sum works correct', function () {
expect(sum(1, 1)).toBe(2);
});
it('difference works correct', function () {
expect(difference(1, 1)).toBe(0);
});
});
22.
describe('tests types', function () {
it('sync', function () {
expect(true).toBeTruthy();
});
it('async', function (done) {
setTimeout(function () {
expect(true).toBeTruthy();
done();
}, 100);
});
});
29. describe('one div with attributes', function () {
var simpleDOMResult = parse(
'<div class="block" data-foo="bar"></div>'
);
var div = simpleDOMResult.childNodes[0];
defaultDivTests(div);
});
Testing Private Methods
39. Karma — Test Runner for JavaScript
Link coming soon…
40. Runner Workflow
var config = readConfig();
config.browsers.each(function(browser){
var result = startBrowser(browser, config.code);
console.output(processingResult(result));
});
77. it('key input add 2 symbols ', function (done) {
define('',
[
'/res/js/modules/dom/domTraverse.js',
'/res/js/modules/inputWithCounter.js'
],
function (traverse, inputWithCounter) {
var initedInput = initInputWithCounterFor(
inputWithCounter,
tmpl2CountersAndWrapper
);
var counterTextNode = findCounter(initedInput, 0, traverse.getTextNode);
var counter2TextNode = findCounter(initedInput, 1, traverse.getTextNode);
var instance = initedInput.instance;
var input = instance.input;
var startValueLength = instance.valueLength;
var valueLength;
effroi.mouse.focus(input);
effroi.keyboard.hit('1', '1');
valueLength = instance.valueLength;
expect(valueLength - startValueLength).toBe(2);
expect(valueLength).toBe(+counterTextNode.nodeValue);
expect(valueLength).toBe(+counter2TextNode.nodeValue);
done();
}
);
});
inputWithCounter Test From m.ok.ru
78. var keyboard = require('effroi').keyboard;
keyboard.focus(element);
keyboard.hit('a');
keyboard.hit('b','c','d');
keyboard.combine(keyboard.CTRL, 'v');
79. describe('angularjs homepage todo list', function () {
it('should add a todo', function () {
browser.get('http://www.angularjs.org');
element(by.model('todoText')).sendKeys('write a protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write a protractor test');
});
});