Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('posts given data as contentType=json', async () => {
fetchMock.mock('https://awesome-stuff.com/api/post-something', {});
await postJSON('https://awesome-stuff.com/api/post-something', {
some: 'attributes'
});
expect(fetchMock.lastUrl()).toEqual('https://awesome-stuff.com/api/post-something');
expect(fetchMock.lastOptions()).toEqual(expect.objectContaining({
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: '{"some":"attributes"}'
}));
});
window.addEventListener(
'palindrom-before-redirect',
handler
);
fetchMock.mock('/newUrl', {
status: 200,
body: '{"hello": "world"}'
});
await palindrom.morphUrl('/newUrl');
await sleep();
assert.equal(firedEvent.detail.href, '/newUrl');
expect(fetchMock.lastUrl()).to.equal('/newUrl');
expect(window.location.pathname).to.equal(
'/newUrl'
);
});
it('Morphing to a URL should NOT issue a request after a canceled event and morphUrl\'s retuned promise should resolve to `false`', async () => {
makeCallback(done, result => {
const uri = fetchMock.lastUrl();
expect(fetchMock.lastUrl()).toBe('/dataFunc');
}),
);
.then((res) => {
expect(res).toMatchSnapshot();
expect(fetchMock.called(url)).toBeTruthy();
expect(fetchMock.lastUrl()).toBe(url);
expect(fetchMock.lastOptions().method).toBe('PATCH');
});
});
.then((res) => {
expect(res).toMatchSnapshot();
expect(fetchMock.called(url)).toBeTruthy();
expect(fetchMock.lastUrl()).toBe(url);
expect(fetchMock.lastOptions().method).toBe('PUT');
});
});
makeCallback(done, result => {
const uri = fetchMock.lastUrl();
expect(fetchMock.lastUrl()).toBe('/dataFunc');
}),
);
.then((res) => {
expect(res).toMatchSnapshot();
expect(fetchMock.called(url)).toBeTruthy();
expect(fetchMock.lastUrl()).toBe(url);
expect(fetchMock.lastOptions().method).toBe('HEAD');
});
});
makeCallback(done, result => {
const uri = fetchMock.lastUrl();
expect(uri).toBe('data');
}),
);
.then((res) => {
expect(res).toMatchSnapshot();
expect(fetchMock.called(url)).toBeTruthy();
expect(fetchMock.lastUrl()).toBe(url);
expect(fetchMock.lastOptions().method).toBe('POST');
});
});