tee-mo-core
Version:
72 lines (60 loc) • 2.16 kB
JavaScript
import {validateModel} from '../src/validation'
const i18n = 'CN', emptyModelList = []
describe("校验model测试", () => {
it("没有定义namespace", () => {
expect(() => {
const model = {}
validateModel(model, emptyModelList, i18n)
}).toThrow(`[teeMo.model] 应该定义 namespace`)
})
it("namespace的类型不是string类型", () => {
expect(() => {
const model = {
namespace: {}
}
validateModel(model, emptyModelList, i18n)
}).toThrow(`[teeMo.model] namespace必须是string类型,当前namespace的类型是 [${typeof {}}]`)
})
it("namespace不唯一的时候", () => {
expect(() => {
const model = {
namespace: "test"
}
const modelList = [{
namespace: "test"
}]
validateModel(model, modelList, i18n)
}).toThrow(`[teeMo.model] namespace必须唯一`)
})
it("reducers不是一个普通的js对象的时候", () => {
expect(() => {
const model = {
namespace: "test",
reducers: 33,
effects: {}
}
validateModel(model, emptyModelList, i18n)
}).toThrow(`[teeMo.model] reducers必须是一个普通的javaScript对象,当前的reducer的类型是 [${typeof 33}]`)
})
it("effects不是一个普通的js对象的时候", () => {
expect(() => {
const model = {
namespace: "test",
reducers: {},
effects: 12
}
validateModel(model, emptyModelList, i18n)
}).toThrow(`[teeMo.model] effects必须是一个普通的javaScript对象,当前的effect的类型是 [${typeof 12}]`)
})
it("正确的model定义", () => {
expect(() => {
const model = {
namespace: "test",
initialState: {},
reducers: {},
effects: {}
}
validateModel(model, emptyModelList, i18n)
}).not.toThrow()
})
})