Hey.
I’ve replaced the default
Browser.site = ‘https://sincere-cone.gomix.me’;
with the following
Browser.localhost(‘localzombie.test’, (process.env.PORT || 3000));
In order to make requests to domain localzombie.test/, by executing the asynchronous callback
suiteSetup(function (done) {
return browser.visit('/', done);
});
which ought a be routed to localhost:3000
.
However, the latter zombie.js test suite just throws error after error:
TypeError: Cannot read property ‘replace’ of undefined.
Hey! This is how I use Zombie with an example project hosted at http://localhost:3000
.
let Browser = require('zombie')
let browser = new Browser()
browser.site = 'http://localhost:3000/'
let name = 'Poppy'
browser.visit('/welcome', () =>{
browser.assert.success()
browser.assert.element('h2#question')
browser.fill('#name', name)
browser.pressButton('#submitname', () => {
browser.assert.text('p#response', 'Welcome ' + name)
console.log('All tests passed')
})
})
It seems to work for me, provided that the express app is running.
I’ll leave the code for the express server and index page below too, just in case:
Express Server:
let express = require('express')
let app = express()
app.listen(3000)
app.get('/welcome', (request, response) => {
response.sendFile(__dirname + '/welcome.html')
})
Welcome Page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h2 id='question'>What is your name?</h2>
<input type='text' name='name' id='name'>
<button id='submitname'
onclick ="document.querySelector('#response').textContent = 'Welcome ' + document.querySelector('#name').value"
>is my name.</button>
<p id='response'></p>
</body>
</html>
Yep, with browser.site It works, since the host is directly specified.
However browser.localhost
should set it to the hostname instead. Whenever you call browser.visit
with any relative URL, with the callback suiteSetup
, It appends the host to Browser.site
without being declared in the code.
I don’t understand why It fails with browser.localhost