本文整理汇总了TypeScript中mocha.before函数的典型用法代码示例。如果您正苦于以下问题:TypeScript before函数的具体用法?TypeScript before怎么用?TypeScript before使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了before函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe("Interpreters", () => {
let context: MetaesContext;
let me;
before(() => {
me = { firstName: "John", lastName: "Named" };
let iterator = 1;
let interpreters = {
values: {
GetProperty({ object }, c, _cerr) {
if (object === me) {
// Intentionally delay
setTimeout(() => c(iterator++));
} else {
// make the `super` call
GetProperty.apply(null, arguments);
}
}
},
prev: ECMAScriptInterpreters
};
context = new MetaesContext(undefined, console.error, { values: { me } }, { interpreters });
});
it("should support custom GetValue", async () => {
assert.deepEqual(await evalFunctionBodyAsPromise({ context, source: me => [me.firstName, me.lastName] }), [1, 2]);
});
});
示例2: describe
describe("From source files tests", async () => {
// generate tests on runtime
before(async () => {
const files = (await pify(glob)(__dirname + "/*.spec.ts")).map(async file => ({
name: file,
contents: (await fs.readFile(file)).toString()
}));
return (await Promise.all(files)).forEach(({ contents, name }) => {
const testNames = contents.match(/\/\/ it: [^\n]+\n/g);
const tests = contents.split(/\/\/ it: .+\n/).filter(line => line.length);
const suiteName = name.substring(name.lastIndexOf("/") + 1);
describe(suiteName, () => {
zip(testNames, tests).forEach(([name, value]) => {
if (name.includes(":skip")) {
return;
}
const testName = name.replace("// it:", "").trim();
it(testName, async () => {
const result = await evaluate(value);
return assert.isTrue(typeof result === "boolean" && result);
});
});
});
});
});
// it is a placeholder to force mocha to run `before` function
it("noop", () => {});
});
示例3: describe
describe("Remote", () => {
let server;
before(async () => {
server = await runWSServer();
});
after(() => server.close());
defineTestsFor("Remote HTTP messaging", () => createHTTPConnector("http://localhost:" + server.address().port));
defineTestsFor("Remote WebSocket messaging", () =>
createWSConnector(W3CWebSocket)(`ws://localhost:` + server.address().port)
);
});
示例4: describeModule
describeModule('component:x-foo', 'TestModule callbacks', function() {
before(function() {
class I18n extends Ember.Object {}
this.skip();
this.timeout(1000);
this.registry.register('helper:i18n', I18n);
this.registry.register('helper:i18n', I18n, { singleton: true });
this.register('service:i18n', {});
this.inject.service('i18n');
this.inject.service('i18n', { as: 'i18n' });
this.factory('object:user').create();
});
after(function() {
});
beforeEach(function() {
});
afterEach(function() {
});
});
示例5: describe
describe('Test mapCss function with icons-only css file', () => {
let fileContent = ''
let map
const expected = {
'fa-glass': '\uf000',
'fa-music': '\uf001',
'fa-search': '\uf002',
'fa-envelope-o': '\uf003',
'fa-heart': '\uf004',
'fa-remove': '\uf00d',
'fa-close': '\uf00d',
'fa-times': '\uf00d',
'fa-gear': '\uf013',
'fa-cog': '\uf013',
'fa-rotate-right': '\uf01e',
'fa-repeat': '\uf01e',
'fa-dedent': '\uf03b',
'fa-outdent': '\uf03b',
'fa-photo': '\uf03e',
'fa-image': '\uf03e',
'fa-picture-o': '\uf03e',
}
before('load css file to test', () => {
try {
fileContent = fs.readFileSync(
require.resolve('./font-awesome.css'),
'utf8'
)
} catch (err) {
throw err
}
})
it('parses without errors', () => {
map = lib.mapCss(fileContent)
})
it('has expected number of keys', () => {
assert.strictEqual(Object.keys(map).length, Object.keys(expected).length)
})
it('has expected keys and values', () => {
const assertPropExistsWithValue = (map, key, value) => {
assert.ok(map.hasOwnProperty(key), `Key "${key}" is missing`)
assert.ok(typeof map[key] === 'string', `Key "${key}" has unexpected type "${typeof map[key]}"`)
assert.strictEqual(
map[key],
value,
`Values for key "${key}" do not match.` +
` Expected: "${value}" (charcode ${value.charCodeAt(0)}),` +
` actual: "${map[key]}" (charcode ${map[key].charCodeAt(0)})`
)
}
Object.keys(expected).forEach((key) => {
assertPropExistsWithValue(map, key, expected[key])
})
})
})
示例6: describe
describe('Test mapCss function with uglified css file from Font Awesome module', () => {
let fileContent = ''
let map
const expected = {
'fa-500px': '\uf26e',
'fa-accessible-icon': '\uf368',
'fa-american-sign-language-interpreting': '\uf2a3',
'fa-youtube': '\uf167',
'fa-youtube-square': '\uf431'
}
before('load css file to test', () => {
try {
fileContent = fs.readFileSync(
require.resolve('@fortawesome/fontawesome-free/css/fontawesome.css'),
'utf8'
)
} catch (err) {
throw err
}
})
it('parses without errors', () => {
map = lib.mapCss(fileContent)
})
it('has expected keys and values', () => {
const assertPropExistsWithValue = (map, key, value) => {
assert.ok(map.hasOwnProperty(key), `Key "${key}" is missing`)
assert.ok(typeof map[key] === 'string', `Key "${key}" has unexpected type "${typeof map[key]}"`)
assert.strictEqual(
map[key],
value,
`Values for key "${key}" do not match.` +
` Expected: "${value}" (charcode ${value.charCodeAt(0)}),` +
` actual: "${map[key]}" (charcode ${map[key].charCodeAt(0)})`
)
}
Object.keys(expected).forEach((key) => {
assertPropExistsWithValue(map, key, expected[key])
})
})
it('each key starts with prefix fa-', () => {
Object.keys(map).forEach((key) => {
assert.ok(key.length >= 3, `Key "${key}" is too short to start with prefix "fa-"`)
assert.strictEqual(key.substring(0, 3), 'fa-', `Key "${key}" has unexpected prefix "${key.substring(0, 3)}"`)
})
})
it('each value is a unicode code point', () => {
Object.keys(map).forEach((key) => {
const value = map[key]
const codePoint = value.charCodeAt(0).toString(16)
assert.ok(typeof value === 'string', `Value "${value}" has unexpected type "${typeof value}"`)
assert.ok(/f[a-f0-9]{3}/i.test(codePoint), `"${codePoint}" doesn't seem to be a unicode code point ${codePoint}`)
})
})
})