+0
日增长
5,621
stars
506
forks
3
watchers
348
prs
881
issues
1
releases
README
Zombie.js
Insanely fast, headless full-stack testing using Node.js
The Bite
If you're going to write an insanely fast, headless browser, how can you not
call it Zombie? Zombie it is.
Zombie.js is a lightweight framework for testing client-side JavaScript code in
a simulated environment. No browser required.
Let's try to sign up to a page and see what happens:
js
const Browser = require('zombie');
// We're going to make requests to http://example.com/signup
// Which will be routed to our test server localhost:3000
Browser.localhost('example.com', 3000);
describe('User visits signup page', function() {
const browser = new Browser();
before(function(done) {
browser.visit('/signup', done);
});
describe('submits form', function() {
before(function(done) {
browser.fill('email', '[email protected]')
.then(() = browser.fill('password', 'eat-the-living'))
.then(() = browser.pressButton('Sign Me Up!', done));
});
it('should be successful', function() {
browser.assert.success();
});
it('should see welcome page', function() {
browser.assert.text('title', 'Welcome To Brains Depot');
});
});
});
This example uses the Mocha testing
framework, but Zombie will work with other testing frameworks. Since Mocha
supports promises, we can also write the test like this:
js
const Browser = require('zombie');
// We're going to make requests to http://example.com/signup
// Which will be routed to our test server localhost:3000
Browser.localhost('example.com', 3000);
describe('User visits signup page', function() {
const browser = new Browser();
before(function() {
return browser.visit('/signup');
});
describe('submits form', function() {
before(function() {
return browser.fill('email', '[email protected]')
.then(() = browser.fill('password', 'eat-the-living'))
.then(() = browser.pressButton('Sign Me Up!'));
});
it('should be successful', function() {
browser.assert.success();
});
it('should see welcome page', function() {
browser.assert.text('title', 'Welcome To Brains Depot');
});
});
});
Well, that was easy.
WARNING: Crawling untrusted web pages with Zombie.js is not safe.
Table of Contents
Installing
Browser
Assertions
Cookies
Tabs
Debugging
Events
Resources
Pipeline
Installing
To install Zombie.js you will need Node.js:
bash
$ npm install zombie --save-dev
Browser
browser.assert
Methods for making assertions against the browser, such as
browser.assert.element('.foo').
See Assertions for detailed discussion.
browser.referer
You can use this to set the HTTP Referer header.
browser.resources
Access to history of retrieved resources. See Resources for
detailed discussion.
browser.pipeline
Access to the pipeline for making requests and processing responses. Use this
to add new request/response handlers the pipeline for a single browser instance,
or Top issues
#882"Did not get to load all resources on this page"34 comments · 2015-03-23#939Upgrade to [email protected]19 comments · 2015-08-21#805ZombieJS and CORS16 comments · 2014-11-20#986How to find a finite resource ?10 comments · 2015-12-10#993Why are tests going though replay proxy9 comments · 2015-12-15#1112How to assert after DOM changes?7 comments · 2017-04-19#909SyntaxError: Use of const in strict mode.7 comments · 2015-04-30#776Complete example using Mocha7 comments · 2014-10-17
Latest release
6.1.4 6.1.4 2018-11-27Updated dependencies