本文整理汇总了TypeScript中chai.assert.fail方法的典型用法代码示例。如果您正苦于以下问题:TypeScript assert.fail方法的具体用法?TypeScript assert.fail怎么用?TypeScript assert.fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chai.assert
的用法示例。
在下文中一共展示了assert.fail方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('resolves only once', async () => {
const deferred = new Deferred<string>();
deferred.resolve('foo');
try {
deferred.resolve('bar');
assert.fail();
} catch (e) {
// pass
}
try {
deferred.reject(new Error('bar'));
assert.fail();
} catch (e) {
// pass
}
});
示例2: it
it(`an inline or anonymous interface must be explicitly annotated with ObjectSchema()`, function () {
try {
class ClassToValidate {
@Keys({
nestedProperty: Joi.number()
})
public myProperty! : {
nestedProperty : number;
};
}
assert.fail();
} catch (err) {
if (!(err instanceof ConstraintDefinitionError)) {
throw err;
}
assert.equal(err.message, "No validation schema exists, nor could it be inferred from the design:type metadata, for property \"myProperty\". Please decorate the property with a type schema.");
}
const validator = new Validator();
class ClassToValidate2 {
@Keys({
nestedProperty: Joi.number()
})
@ObjectSchema()
public myProperty! : {
nestedProperty : number;
};
}
const instance = new ClassToValidate2();
instance.myProperty = {
nestedProperty: 123
};
isValid(validator, instance);
});
示例3: it
it('should get the next game in a circular loop', () => {
const countsPerGame: Dict<number> = {};
const firstGameName: GameName = 'piano-game';
let currentGameName: GameName = firstGameName;
let loopCount = 0;
while (true) {
currentGameName = getNextGame(currentGameName);
// Track the number of times we see each game so we can ensure that it circles back.
countsPerGame[currentGameName] = (countsPerGame[currentGameName] || 0) + 1;
// Break when we circle back to the first game
if (currentGameName === firstGameName) {
break;
}
// Sanity check the loop count in case the exit condition never hits.
loopCount++;
if (loopCount > 999) {
assert.fail('Looped way too many times - getting the next game name should be circular.');
break;
}
}
assert(
values(countsPerGame).every((count: number) => count === 1),
'should have looped through each game once'
);
assert.equal(
Object.keys(countsPerGame).length,
3,
'expected to loop through exactly 3 game names'
);
});
示例4: catch
function checkNoOpHandler<T>(requestInfo: RequestInfo<T>): void {
try {
requestInfo.handler(fakeXhrIo({}), '');
} catch (e) {
assert.fail('Remove handler threw');
}
}
示例5: it
it('creates externs, adds type comments and rewrites imports', () => {
const diagnostics: ts.Diagnostic[] = [];
const closure = toClosureJS(
{sourceMap: true, experimentalDecorators: true} as ts.CompilerOptions,
['test_files/underscore/export_underscore.ts', 'test_files/underscore/underscore.ts'],
{isTyped: true}, diagnostics);
if (!closure) {
diagnostics.forEach(v => console.log(JSON.stringify(v)));
assert.fail();
return;
}
expect(closure.externs).to.contain(`/** @const */
var __NS = {};
/** @type {number} */
__NS.__ns1;
`);
const underscoreDotJs = closure.jsFiles.get('test_files/underscore/underscore.js');
expect(underscoreDotJs).to.contain(`goog.module('test_files.underscore.underscore')`);
expect(underscoreDotJs).to.contain(`/** @type {string} */`);
const exportUnderscoreDotJs = closure.jsFiles.get('test_files/underscore/export_underscore.js');
expect(exportUnderscoreDotJs)
.to.contain(`goog.module('test_files.underscore.export_underscore')`);
});
示例6: it
it ('Can authenticate with BearerToken', async () => {
var request = new Authenticate();
request.provider = "credentials";
request.userName = "test";
request.password = "test";
var authResponse = await testClient.post(request);
var jwtToken = authResponse.bearerToken;
chai.expect(jwtToken).not.empty;
//Clear existing User Session
var logout = new Authenticate();
logout.provider = "logout";
await testClient.post(logout);
var newClient = new JsonServiceClient(TEST_URL);
try {
//New Client without BearerToken should fail
await newClient.post(new Authenticate());
chai.assert.fail(0,1, "Should not be allowed to authenticate");
} catch (e) {
if (e instanceof chai.AssertionError)
throw e;
const status = (e as ErrorResponse).responseStatus;
chai.expect(status.errorCode).to.equal("401");
chai.expect(status.message).to.equal("Unauthorized");
//New Client with BearerToken
newClient.bearerToken = jwtToken;
var success = await newClient.post(new Authenticate());
chai.expect(success.userId).not.empty;
chai.expect(success.sessionId).not.empty;
}
})
示例7: it
it("should verify ParseXml - invalid xml input", async function() {
try {
await CommandHelper.ParseXml("<?xml><<<<");
assert.fail("didn't throw!");
} catch (err) {
assert.isTrue(err.message.startsWith("Unexpected end"));
}
});
示例8: assertError
export function assertError(fn: () => any, code: string) {
try {
fn();
} catch (e) {
assert.equal(e.code, code);
return;
}
assert.fail();
}
示例9: function
helper.dataDrivenTest(tests, function(data, expect) {
try {
parse(data);
} catch (e) {
assert.match(e.message, expect);
return;
}
assert.fail(undefined, undefined, "No exception thrown.");
});
示例10: it
it("should throw an error if the same actionNamespace is used twice", function () {
new CachedDataReducer<Request, Response>(apiEndpointMock, "duplicatenamespace");
try {
new CachedDataReducer<Request, Response>(apiEndpointMock, "duplicatenamespace");
} catch (e) {
assert(_.isError(e));
return;
}
assert.fail("Expected to fail after registering a duplicate actionNamespace.");
});