console.log(‘About me’);
●
●
●
●
●
●
●
●
●
describe('render()', function() {
it('should render the ad', function() {
var advert = new Advert(adConfig);
advert.render();
expect(advert.rendered).to.be.true;
});
});
$ grunt test-unit:RichMediaLib
$ grunt test-e2e:RichMediaLib
<!-- index.html -->
<html>
<body>
<script src="http://onecreative.aol.com/jsapi/ONE.js"></script>
<button onclick="ONE.click()">Buy me!</button>
</body>
</html> // test.js
module.exports = {
'Test click': function(browser) {
browser
.url('index.html')
.waitForElementPresent('button')
.click('button')
.url(function(url) {
browser.assertEquals(url, 'http://redirect.com');
})
.end();
}
};
$ grunt test-unit-cloud:RichMediaLib
$ grunt test-e2e-cloud:RichMediaLib
// test.js
module.exports = {
'Test click': function(browser) {
browser
.url('index.html')
.waitForElementPresent('button')
.click('button')
.url(function(url) {
browser.assertEquals(url, 'http://redirect.com');
})
.end();
}
};
describe('render()', function() {
it('should render the ad', function() {
var advert = new Advert(adConfig);
advert.render();
expect(advert.rendered).to.be.true;
});
});
describe('GET /ads/{id}/events', () => {
it('should respond with events as JSON', done => {
request(server)
.get('/ads/123/events')
.expect(200)
.end((err, response) => {
expect(response.body).to.be.an('object').with.all.keys('render', 'view');
done(err);
});
});
});
$ npm test
$ ./docker-test.sh
●
●
●
●
●
●
●
describe('setName()', function() {
it('should set name property', function() {
...
});
});
test('adds 1 + 2 to equal 3', () => {
...
});
var callback = sinon.stub();
callback.withArgs(42).returns(1);
callback.withArgs(1).throws("TypeError");
var callback = sinon.stub();
callback.onCall(0).returns(1);
callback.onCall(1).returns(2);
callback.returns(3);
foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.lengthOf(3);
tea.should.have.property('flavors')
.with.lengthOf(3);
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
expect(tea).to.have.property('flavors')
.with.lengthOf(3);
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●

Testing in JavaScript

  • 2.
  • 4.
  • 8.
    describe('render()', function() { it('shouldrender the ad', function() { var advert = new Advert(adConfig); advert.render(); expect(advert.rendered).to.be.true; }); }); $ grunt test-unit:RichMediaLib
  • 9.
    $ grunt test-e2e:RichMediaLib <!--index.html --> <html> <body> <script src="http://onecreative.aol.com/jsapi/ONE.js"></script> <button onclick="ONE.click()">Buy me!</button> </body> </html> // test.js module.exports = { 'Test click': function(browser) { browser .url('index.html') .waitForElementPresent('button') .click('button') .url(function(url) { browser.assertEquals(url, 'http://redirect.com'); }) .end(); } };
  • 12.
    $ grunt test-unit-cloud:RichMediaLib $grunt test-e2e-cloud:RichMediaLib // test.js module.exports = { 'Test click': function(browser) { browser .url('index.html') .waitForElementPresent('button') .click('button') .url(function(url) { browser.assertEquals(url, 'http://redirect.com'); }) .end(); } }; describe('render()', function() { it('should render the ad', function() { var advert = new Advert(adConfig); advert.render(); expect(advert.rendered).to.be.true; }); });
  • 13.
    describe('GET /ads/{id}/events', ()=> { it('should respond with events as JSON', done => { request(server) .get('/ads/123/events') .expect(200) .end((err, response) => { expect(response.body).to.be.an('object').with.all.keys('render', 'view'); done(err); }); }); }); $ npm test
  • 14.
  • 16.
  • 17.
    describe('setName()', function() { it('shouldset name property', function() { ... }); }); test('adds 1 + 2 to equal 3', () => { ... });
  • 18.
    var callback =sinon.stub(); callback.withArgs(42).returns(1); callback.withArgs(1).throws("TypeError"); var callback = sinon.stub(); callback.onCall(0).returns(1); callback.onCall(1).returns(2); callback.returns(3); foo.should.be.a('string'); foo.should.equal('bar'); foo.should.have.lengthOf(3); tea.should.have.property('flavors') .with.lengthOf(3); expect(foo).to.be.a('string'); expect(foo).to.equal('bar'); expect(foo).to.have.lengthOf(3); expect(tea).to.have.property('flavors') .with.lengthOf(3);
  • 21.
  • 22.