source: node_modules/simple-update-notifier/src/getDistVersion.spec.ts

main
Last change on this file was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 810 bytes
RevLine 
[81bc7da]1import Stream from 'stream';
2import https from 'https';
3import getDistVersion from './getDistVersion';
4
5jest.mock('https', () => ({
6 get: jest.fn(),
7}));
8
9test('Valid response returns version', async () => {
10 const st = new Stream();
11 (https.get as jest.Mock).mockImplementation((url, cb) => {
12 cb(st);
13
14 st.emit('data', '{"latest":"1.0.0"}');
15 st.emit('end');
16 });
17
18 const version = await getDistVersion('test', 'latest');
19
20 expect(version).toEqual('1.0.0');
21});
22
23test('Invalid response throws error', async () => {
24 const st = new Stream();
25 (https.get as jest.Mock).mockImplementation((url, cb) => {
26 cb(st);
27
28 st.emit('data', 'some invalid json');
29 st.emit('end');
30 });
31
32 expect(getDistVersion('test', 'latest')).rejects.toThrow(
33 'Could not parse version response'
34 );
35});
Note: See TracBrowser for help on using the repository browser.