Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Dec 11, 2024
1 parent f0b8c5e commit 10b9503
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions assets/@hugomods/jsend/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from '@jest/globals';
import jsend from './index';
import { JSend } from './index';

test('fail without data', () => {
const rst = JSON.parse(JSON.stringify(jsend.fail()));
const rst = JSON.parse(JSON.stringify(JSend.fail()));
expect(rst.status).toBe('fail');
expect(rst.data).toBeNull();
});
Expand All @@ -13,22 +13,22 @@ test('fail with data', () => {
title: 'The title is required.',
},
};
const rst = JSON.parse(JSON.stringify(jsend.fail(data)));
const rst = JSON.parse(JSON.stringify(JSend.fail(data)));
expect(rst.status).toBe('fail');
expect(rst.data).toStrictEqual(data);
});

test('error with message', () => {
const message = 'ERROR';
const rst = JSON.parse(JSON.stringify(jsend.error(message)));
const rst = JSON.parse(JSON.stringify(JSend.error(message)));
expect(rst.status).toBe('error');
expect(rst.message).toStrictEqual(message);
});

test('error with message and code', () => {
const message = 'ERROR';
const code = 10000;
const rst = JSON.parse(JSON.stringify(jsend.error(message, code)));
const rst = JSON.parse(JSON.stringify(JSend.error(message, code)));
expect(rst.status).toBe('error');
expect(rst.message).toStrictEqual(message);
expect(rst.code).toStrictEqual(code);
Expand All @@ -46,14 +46,14 @@ test('error with message, code and data', () => {
},
],
};
const rst = JSON.parse(JSON.stringify(jsend.error(message, code, data)));
const rst = JSON.parse(JSON.stringify(JSend.error(message, code, data)));
expect(rst.status).toBe('error');
expect(rst.message).toStrictEqual(message);
expect(rst.code).toStrictEqual(code);
});

test('success without data', () => {
const rst = JSON.parse(JSON.stringify(jsend.success()));
const rst = JSON.parse(JSON.stringify(JSend.success()));
expect(rst.status).toBe('success');
expect(rst.data).toBeNull();
});
Expand All @@ -70,7 +70,7 @@ test('success with data', () => {
],
page: 1,
};
const rst = JSON.parse(JSON.stringify(jsend.success(data)));
const rst = JSON.parse(JSON.stringify(JSend.success(data)));
expect(rst.status).toBe('success');
expect(rst.data).toStrictEqual(data);
});

0 comments on commit 10b9503

Please sign in to comment.