SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
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);
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●

Weitere ähnliche Inhalte

Was ist angesagt?

Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
DataArt
 

Was ist angesagt? (9)

Automation build
Automation buildAutomation build
Automation build
 
WordPress Customizer
WordPress CustomizerWordPress Customizer
WordPress Customizer
 
Angular 2のRenderer
Angular 2のRendererAngular 2のRenderer
Angular 2のRenderer
 
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
 
Google Tag Manager
Google Tag ManagerGoogle Tag Manager
Google Tag Manager
 
Web components v1 intro
Web components v1 introWeb components v1 intro
Web components v1 intro
 
">&lt;img src="x">
">&lt;img src="x">">&lt;img src="x">
">&lt;img src="x">
 
Working With Ajax Frameworks
Working With Ajax FrameworksWorking With Ajax Frameworks
Working With Ajax Frameworks
 
Tools20121015
Tools20121015Tools20121015
Tools20121015
 

Testing in JavaScript

  • 1.
  • 3.
  • 5.
  • 6.
  • 7.
  • 8. 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
  • 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(); } };
  • 10.
  • 11.
  • 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
  • 15.
  • 17. describe('setName()', function() { it('should set 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);
  • 19.
  • 20.