Created
September 20, 2018 00:21
-
-
Save manobi/7c834d1d3b9627d8d786690949619d8b to your computer and use it in GitHub Desktop.
Pollyjs do not persist nor intercept anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {expect} = require('chai'); | |
const fetch = require('node-fetch'); | |
const Polly = require('@pollyjs/core').Polly; | |
const FetchAdapter = require('@pollyjs/adapter-fetch'); | |
const FSPersister = require('@pollyjs/persister-fs'); | |
global.fetch = fetch; | |
global.Request = fetch.Request; | |
global.Response = fetch.Response; | |
global.Headers = fetch.Headers; | |
Polly.register(FetchAdapter); | |
Polly.register(FSPersister); | |
const polly = new Polly('dogs api', { | |
adapters: ['fetch'], | |
persister: 'fs' | |
}); | |
const DOMAIN = 'dog.ceo'; | |
const APPLICATION_URL = `https://${DOMAIN}`; | |
const BASE_URL = `${APPLICATION_URL}/api/breeds/image/random`; | |
polly.record(); | |
const { server } = polly; | |
describe('Login', function() { | |
this.timeout(5000); | |
before(async () => { | |
server.get(`*`).intercept((req, res) => { | |
console.log('intercepted'); | |
res.status(200); | |
return res.json({ok: false}); | |
}); | |
}); | |
after(() => { | |
return polly.stop(); | |
}); | |
describe('GET /login', () => { | |
it('get a random dog', () => { | |
return fetch(`${BASE_URL}/login`, { | |
method: 'GET', | |
headers: { 'Content-Type': 'application/json' } | |
}) | |
.then(async (res) => { | |
const data = await res.json(); | |
// Will always fall | |
expect(data).to.be.deep.equal({ok:true}) | |
}); | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment