Skip to content

Instantly share code, notes, and snippets.

@Tallyb
Created June 7, 2019 18:20
Show Gist options
  • Save Tallyb/6023452c33d1a73b3cd3ff1d5e28e315 to your computer and use it in GitHub Desktop.
Save Tallyb/6023452c33d1a73b3cd3ff1d5e28e315 to your computer and use it in GitHub Desktop.
Fetch spec
import { newSpecPage } from '@stencil/core/testing';
import { MyFetchComponent } from './fetch';
describe('fetch', () => {
it('should render with language', async () => {
const fetchMock = jest.fn().mockImplementation( v => {
return Promise.resolve({
ok: true,
json: jest.fn().mockImplementation(() => Promise.resolve({}))
});
});
Object.defineProperty(global, 'fetch', {
value: fetchMock,
writable: true
});
const html = `
<my-fetch language="fr">
<p> This is the app </p>
</my-fetch>
`
const page = await newSpecPage({
components: [MyFetchComponent],
html
});
expect(fetchMock).toHaveBeenCalledWith('./assets/i18n/fr.json');
page.root.language = "he";
await page.waitForChanges();
expect(fetchMock).toHaveBeenCalledWith('./assets/i18n/he.json');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment