typescript users.spec.ts

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript users.spec.ts相关的知识,希望对你有一定的参考价值。

import { Users } from './users';
import { Http } from './common/http';
// the following line will instruct Jest
// to use the mock class instead of the real one
jest.mock('./common/http');

describe('Users', () => {
    let instance: Users;

    beforeEach(() => {
        instance = new Users();
    });

    it('should get all users as an array', async () => {
        expect(instance).toBeInstanceOf(Users);
        const allUsers = await instance.all();
        expect(allUsers).toBeDefined();
        expect(allUsers[0]).toBeDefined();
    });

    it('should get receive an error', async () => {
        Http.prototype.get = jest.fn().mockImplementationOnce(() => {
            return new Error('Something weird happened');
        });
        const error: Error = await instance.all();
        expect(error).toBeInstanceOf(Error);
        expect(error.message).toBe('Something weird happened')
    });
});

以上是关于typescript users.spec.ts的主要内容,如果未能解决你的问题,请参考以下文章

typescript TypeScript Snippets #typescript

TypeScript入门五:TypeScript的接口

TypeScript系列教程--初探TypeScript

TypeScript入门三:TypeScript函数类型

typescript使用 TypeScript 开发 Vue 组件

认识 TypeScript