mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 10:54:49 +00:00
25 lines
694 B
JavaScript
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' })
|
||
|
})
|
||
|
})
|