本文整理匯總了TypeScript中QUnit.test函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript test函數的具體用法?TypeScript test怎麽用?TypeScript test使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了test函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: run
public run(): void {
QUnit.test("hello test", (assert) => {
assert.ok(1 === 1, "Passed!");
});
//
QUnit.test("Promise test", (assert) => {
var done = assert.async();
test_func().then((r: string) => {
assert.ok(true, 'text is ' + r);
done();
}).catch((err) => {
assert.ok(false, err.toString());
done();
});
});
//
QUnit.test("PouchDatabase test", (assert) => {
var done = assert.async();
let base = new PouchDatabase();
base.db.then((xdb) => {
assert.ok((xdb !== undefined) && (xdb !== null), "db OK!");
done();
},(ex)=>{
assert.ok(false, ex.toString());
done();
}).catch((err) => {
assert.ok(false, err.toString());
done();
});
});
}// run
示例2: module
module('the params belong to a different user', function(hooks) {
const escapedName = 'Test%20User';
const publicKey = '53edcbe7d1cdd289e9f4ea74eab12c6dd78720124efd9ad331d6e174aae5677c';
hooks.beforeEach(async function() {
const url = `/invite?name=${escapedName}&publicKey=${publicKey}`;
await visit(url);
});
test('a redirect to the correct direct message chat', function(assert) {
assert.expect(1);
assert.equal(currentURL(), `/chat/privately-with/${publicKey}`);
percySnapshot(assert as any);
});
test('the contact is added to the list of contacts', async function(assert) {
const store = getService<DS.Store>('store');
const record = await store.findRecord('contact', publicKey);
assert.ok(record);
});
});
示例3: module
module('Integration | Component | search/search-facet', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function(assert) {
await createTest(this);
assert.equal(getTextNoSpaces(this), 'Facet1Value11Value210');
});
test('it renders with clear', async function(assert) {
await createTest(this, { value1: true });
assert.equal(getTextNoSpaces(this), 'Facet1clearValue11Value210');
});
test('clear action', async function(assert) {
const { wasClearCalled } = await createTest(this, { value1: true });
assert.equal(getTextNoSpaces(this), 'Facet1clearValue11Value210');
await click(CLEAR_BTN_SELECTOR);
assert.ok(wasClearCalled(), 'Clear was called');
});
test('facet changed action', async function(assert) {
const { wasChangedCalled } = await createTest(this, { value1: true });
assert.equal(getTextNoSpaces(this), 'Facet1clearValue11Value210');
await click(FACET_OPTION_SELECTOR);
assert.ok(wasChangedCalled(), 'Clear was called');
});
});
示例4: module
module('Acceptance | search', function(hooks) {
setupApplicationTest(hooks);
test('Search does not through an error when typing', async function(assert) {
await appLogin();
await visit('/');
assert.equal(currentURL(), '/browse/datasets', 'We made it to the home page in one piece');
fillIn(searchBarSelector, 'Hello darkness my old friend');
assert.ok(true, 'Did not encounter an error when filling in search bar');
});
test('visiting /search and restoring facet selections', async function(assert) {
await appLogin();
await visit('/search?facets=(fabric%3AList(prod%2Ccorp))&keyword=car');
assert.equal(currentURL(), '/search?facets=(fabric%3AList(prod%2Ccorp))&keyword=car');
const { prod, corp, dev, ei } = getCheckboxes(this);
const searchBar = querySelector<HTMLInputElement>(this, searchBarSelector) || { value: '' };
assert.ok(prod.checked);
assert.ok(corp.checked);
assert.notOk(dev.checked);
assert.notOk(ei.checked);
assert.equal(searchBar.value, 'car');
await click(getCheckboxSelector('ei'));
assert.equal(currentURL(), '/search?facets=(fabric%3AList(prod%2Ccorp%2Cei))&keyword=car');
});
});
示例5: module
module('yourself', function(hooks) {
setupRelayConnectionMocks(hooks);
hooks.beforeEach(async function() {
await visit('/chat/privately-with/me');
});
test('page renders with default states', function(assert) {
assert.equal(currentURL(), '/chat/privately-with/me');
assert.notOk(chat.textarea.isDisabled(), 'textarea is enabled');
assert.ok(chat.submitButton.isDisabled(), 'submit button is disabled');
assert.equal(chat.messages.all().length, 0, 'history is blank');
});
test('there are 0 messages to start with', function(assert) {
const result = chat.messages.all().length;
assert.equal(result, 0);
});
module('text is entered', function(hooks) {
hooks.beforeEach(async function() {
await chat.textarea.fillIn('a message');
});
test('the chat button is not disabled', function(assert) {
assert.notOk(chat.submitButton.isDisabled());
});
module('submit is clicked', function(hooks) {
hooks.beforeEach(async function() {
chat.submitButton.click();
await waitFor(chat.selectors.submitButton + '[disabled]');
});
test('inputs are disabled', function(assert) {
// assert.equal(chat.messages.all().length, 0, 'history is blank');
// assert.ok(chat.textarea.isDisabled(), 'textarea is disabled');
assert.ok(chat.submitButton.isDisabled(), 'submitButton is disabled');
percySnapshot(assert as any);
});
});
module('enter is pressed', function(hooks) {
hooks.beforeEach(async function() {
triggerEvent(chat.selectors.form, 'submit');
await waitFor(chat.selectors.submitButton + '[disabled]');
});
test('inputs are disabled', function(assert) {
// assert.ok(chat.textarea.isDisabled(), 'textarea is disabled');
assert.ok(chat.submitButton.isDisabled(), 'submitButton is disabled');
percySnapshot(assert as any);
});
});
});
});
示例6: module
module('Unit | Utility | debug logger', function(hooks) {
let log: SinonStub;
hooks.beforeEach(function() {
debug.enable('test:sample-key');
log = sinon.stub(console, 'log');
});
hooks.afterEach(function() {
debug.disable();
log.restore();
});
test('it honors an explicit key', function(assert) {
const logger = debugLogger('test:sample-key');
logger('placeholder message');
let [message] = A(log.args).get('lastObject') || [''];
assert.ok(/test:sample-key/.test(message), 'Log entry should contain the namespace');
assert.ok(/placeholder message/.test(message), 'Log entry should contain the message');
});
test('it throws with a useful message when it can\'t determine a key', function(assert) {
const logger = debugLogger();
assert.throws(function() {
logger('message');
}, /explicit key/);
assert.throws(function() {
let object = { debug: logger };
object.debug('message');
}, /explicit key/);
});
});
示例7: module
module('TestHelper | create-current-user', function(hooks) {
setupApplicationTest(hooks);
clearLocalStorage(hooks);
test('a new user is created and kept in cache', async function(assert) {
const before = getStore().peekAll('user');
assert.equal(before.length, 0);
await createCurrentUser();
const after = getStore().peekAll('user');
assert.equal(after.length, 1);
assert.equal(after.toArray()[0].id, 'me');
});
test('a new user is created and stored', async function(assert) {
const before = await getStore().findAll('user');
assert.equal(before.length, 0);
await createCurrentUser();
const after = await getStore().findAll('user');
assert.equal(after.length, 1);
assert.equal(after.toArray()[0].id, 'me');
});
test('the user is set on the identity service', async function(assert) {
const before = getService<CurrentUserService>('currentUser').record;
assert.notOk(before);
const user = await createCurrentUser();
const after = getService<CurrentUserService>('currentUser').record;
assert.deepEqual(after, user);
});
module('user is setup in a beforeEach', function(hooks) {
setupCurrentUser(hooks);
test('the user is logged in', function(assert) {
const isLoggedIn = getService<CurrentUserService>('currentUser').isLoggedIn;
assert.ok(isLoggedIn);
});
test('identity exists', async function(assert) {
const exists = await getService<CurrentUserService>('currentUser').exists();
assert.ok(exists);
});
});
});
示例8: module
module('Unit | Utility | nacl', function() {
test('libsodium uses wasm', async function(assert) {
const sodium = await nacl.libsodium();
const isUsingWasm = (sodium as any).libsodium.usingWasm;
assert.ok(isUsingWasm);
});
test('generateAsymmetricKeys | works', async function(assert) {
const boxKeys = await nacl.generateAsymmetricKeys();
assert.ok(boxKeys.publicKey);
assert.ok(boxKeys.privateKey);
});
test('encryptFor/decryptFrom | works with Uint8Array', async function(assert) {
const receiver = await nacl.generateAsymmetricKeys();
const sender = await nacl.generateAsymmetricKeys();
const msgAsUint8 = Uint8Array.from([104, 101, 108, 108, 111]); // hello
const ciphertext = await nacl.encryptFor(msgAsUint8, receiver.publicKey, sender.privateKey);
const decrypted = await nacl.decryptFrom(ciphertext, sender.publicKey, receiver.privateKey);
assert.deepEqual(msgAsUint8, decrypted);
});
test('encryptFor/decryptFrom | works with large data', async function(assert) {
const receiver = await nacl.generateAsymmetricKeys();
const sender = await nacl.generateAsymmetricKeys();
let bigMsg: number[] = [];
for (let i = 0; i < 128; i++) {
bigMsg = bigMsg.concat([104, 101, 108, 108, 111]);
}
const msgAsUint8 = Uint8Array.from(bigMsg); // hello * 128 = 640 Bytes
const ciphertext = await nacl.encryptFor(msgAsUint8, receiver.publicKey, sender.privateKey);
const decrypted = await nacl.decryptFrom(ciphertext, sender.publicKey, receiver.privateKey);
assert.deepEqual(msgAsUint8, decrypted);
});
test('splitNonceFromMessage | separates the nonce', async function(assert) {
// prettier-ignore
const msg = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
];
const messageWithNonce = Uint8Array.from([...msg, 25]);
const [nonce, notTheNonce] = await nacl.splitNonceFromMessage(messageWithNonce);
assert.deepEqual(nonce, Uint8Array.from(msg));
assert.deepEqual(notTheNonce, Uint8Array.from([25]));
});
});