@senacor/azure-function-middleware
Version:
Middleware for azure functions to handle authentication, authorization, error handling and logging
37 lines (36 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const error_1 = require("../error");
const stringify_1 = require("./stringify");
describe('stringify should', () => {
it('return string unmodified', () => {
const input = 'test string';
expect((0, stringify_1.stringify)(input)).toEqual(input);
});
it('stringifies an error object with message and stack', () => {
const error = new error_1.ApplicationError('conflict', 409);
expect((0, stringify_1.stringify)(error)).toContain(error.message);
});
it('stringifies a plain object correctly', () => {
const input = { key: 'value' };
expect((0, stringify_1.stringify)(input)).toBe("{ key: 'value' }");
});
it('process number correctly', () => {
expect((0, stringify_1.stringify)(123)).toBe('123');
});
it('join multiple arguments with spaces', () => {
expect((0, stringify_1.stringify)('Test', 2, { message: 'World' })).toBe("Test 2 { message: 'World' }");
});
it('do not print all items of large arrays', () => {
var _a;
expect((_a = (0, stringify_1.stringify)(Array(250).fill(1)).match(/1/g)) === null || _a === void 0 ? void 0 : _a.length).toBeLessThan(250);
});
it('use toJSON function if available', () => {
const input = {
toJSON: () => ({
value: 42,
}),
};
expect((0, stringify_1.stringify)(input)).toEqual('{"value":42}');
});
});