Nuxt/packages/utils/test/context.test.js
2019-01-29 22:53:42 +03:30

25 lines
694 B
JavaScript

import { getContext, determineGlobals } from '../src/context'
describe('util: context', () => {
test('should get context with req and res', () => {
const ctx = getContext({ a: 1 }, { b: 2 })
expect(getContext.length).toBe(2)
expect(typeof ctx.req).toBe('object')
expect(typeof ctx.res).toBe('object')
expect(ctx.req.a).toBe(1)
expect(ctx.res.b).toBe(2)
})
test('should get correct globals', () => {
const globals = {
foo: name => `${name}: foo`,
bar: name => `${name}: bar`,
baz: 'baz'
}
const result = determineGlobals('global', globals)
expect(result).toEqual({ bar: 'global: bar', foo: 'global: foo', baz: 'baz' })
})
})