mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
import { serializeFunction } from '../src/serialize'
|
|
|
|
describe('util: serialize', () => {
|
|
test('should serialize normal function', () => {
|
|
const obj = {
|
|
fn: function () {}
|
|
}
|
|
expect(serializeFunction(obj.fn)).toEqual('function () {}')
|
|
})
|
|
|
|
test('should serialize shorthand function', () => {
|
|
const obj = {
|
|
fn() {}
|
|
}
|
|
expect(serializeFunction(obj.fn)).toEqual('function() {}')
|
|
})
|
|
|
|
test('should serialize arrow function', () => {
|
|
const obj = {
|
|
fn: () => {}
|
|
}
|
|
expect(serializeFunction(obj.fn)).toEqual('() => {}')
|
|
})
|
|
|
|
test('should not replace custom scripts', () => {
|
|
const obj = {
|
|
fn() {
|
|
return 'function xyz(){};a=false?true:xyz();'
|
|
}
|
|
}
|
|
|
|
expect(serializeFunction(obj.fn)).toEqual(`function () {
|
|
return 'function xyz(){};a=false?true:xyz();';
|
|
}`)
|
|
})
|
|
|
|
test('should serialize internal function', () => {
|
|
const obj = {
|
|
fn(arg) {
|
|
if (arg) {
|
|
return {
|
|
title() {
|
|
return 'test'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
expect(serializeFunction(obj.fn)).toEqual(`function(arg) {
|
|
if (arg) {
|
|
return {
|
|
title: function () {
|
|
return 'test';
|
|
}
|
|
|
|
};
|
|
}
|
|
}`)
|
|
})
|
|
})
|