util#isRegExp TypeScript Examples

The following examples show how to use util#isRegExp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: nexpect.ts    From amplify-codegen with Apache License 2.0 6 votes vote down vote up
function testExpectation(data: string, expectation: string | RegExp, context: Context): boolean {
  if (isRegExp(expectation)) {
    return expectation.test(data);
  } else if (context.ignoreCase) {
    return data.toLowerCase().indexOf(expectation.toLowerCase()) > -1;
  } else {
    return data.indexOf(expectation) > -1;
  }
}
Example #2
Source File: nexpect.ts    From amplify-codegen with Apache License 2.0 6 votes vote down vote up
function createExpectationError(expected: string | RegExp, actual: string) {
  var expectation;
  if (isRegExp(expected)) {
    expectation = 'to match ' + expected;
  } else {
    expectation = 'to contain ' + JSON.stringify(expected);
  }

  var err = new AssertionError({
    message: format('expected %j %s', actual, expectation),
    actual: actual,
    expected: expected,
  });
  return err;
}