Testing in JavaScript9. $ 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
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);