Пример #1
0
	export function assertUnorderedLike<T>(actual:T[], expected:T[], matcher:IsLikeCB<T>, assertion:AssertCB<T>, message:string) {
		assert.isArray(actual, 'actual');
		assert.isArray(expected, 'expected');
		assert.isFunction(matcher, 'matcher');
		assert.isFunction(assertion, 'assertion');
		assert.strictEqual(actual.length, expected.length, message + ': length not equal: ' + actual.length + ' != ' + expected.length);

		// clones
		var actualQueue = actual.slice(0);
		var expectedQueue = expected.slice(0);

		outer : while (actualQueue.length > 0) {
			var act = actualQueue.pop();
			for (var i = 0, ii = expectedQueue.length; i < ii; i++) {
				var exp = expectedQueue[i];

				// check if this combination should be asserted
				if (matcher(act, exp)) {
					// do assertion
					assertion(act, exp, message);
					expectedQueue.splice(i, 1);
					// jump
					continue outer;
				}
			}
			// use assert.deepEqual for diff report
			// assert(false, message + ': no matching element for actual: ' + xm.toValueStrim(act));
			assert.deepEqual([act], expectedQueue, message + ': no matching element for actual: ' + xm.toValueStrim(act));
		}
		// also bad
		if (expectedQueue.length > 0) {
			// use deepEqual for nice report
			assert.deepEqual([], expectedQueue, message + ': remaining expect elements: ' + expectedQueue.length);
		}
	}
  @test('If no page option is specified, first page is returned')
  public async firstPageByDefault() {
    let result = await getAllOrders();
    let firstPageResult = await getAllOrders({ page: 1 });
    assert.isArray(result, 'Expected result to be an array');
    assert.isArray(firstPageResult, 'Expected result to be an array');

    assert.deepEqual(
      result[0],
      firstPageResult[0],
      'First item is the same, regardless of whether page=1 or page option is not provided at all'
    );
  }
Пример #3
0
Файл: CLI.ts Проект: HansS/tsd
	function getArgs(test, data, info:helper.TestInfo):string[] {
		assert.isObject(test, 'test');
		assert.isObject(data, 'data');
		assert.instanceOf(info, helper.TestInfo, 'info');

		var args:string[] = [];

		if (test.command) {
			assert.isArray(test.command, 'test.command');
			args.push.apply(args, test.command);
		}
		else if (data.command) {
			assert.isArray(data.command, 'data.command');
			args.push.apply(args, data.command);
		}

		if (test.query) {
			if (test.query.pattern) {
				args.push(test.query.pattern);
			}
			if (test.query.overwrite) {
				args.push('--overwrite');
			}
			if (test.query.resolve) {
				args.push('--resolve');
			}
			if (test.query.save) {
				args.push('--save');
			}
		}

		if (test.style) {
			args.push('--style', test.style);
		}
		else {
			args.push('--style', 'plain');
		}

		args.push('--progress', 'no');
		args.push('--services', 'no');
		args.push('--cacheMode', xm.http.CacheMode[helper.settings.cache]);

		args.push('--cacheDir', info.cacheDirTestFixed);
		args.push('--config', path.resolve('./test/fixtures/config/default.json'));

		// TODO also write a .bat/.cmd and a shell script; with absolute paths etc (for lazy re-run)
		xm.file.writeJSONSync(info.argsDump, {list: args, flat: args.join(' ')});

		return args;
	}
Пример #4
0
export function assertCoords(coords: coord) {
  assert.isArray(coords);
  assert.lengthOf(coords, 2);

  assert.approximately(coords[0], 13, 1);
  assert.approximately(coords[1], 51, 3);
}
Пример #5
0
      it("sendBatches correctly batches multiple requests", function () {
        const shortRequests = [
          metrics.requestMetrics("id", createRequest(shortTimespan, "short.1")).payload,
          metrics.requestMetrics("id", createRequest(shortTimespan, "short.2", "short.3")).payload,
          metrics.requestMetrics("id", createRequest(shortTimespan, "short.4")).payload,
        ];
        const longRequests = [
          metrics.requestMetrics("id", createRequest(longTimespan, "long.1")).payload,
          metrics.requestMetrics("id", createRequest(longTimespan, "long.2", "long.3")).payload,
          metrics.requestMetrics("id", createRequest(longTimespan, "long.4", "long.5")).payload,
        ];

        // Mix the requests together and send the combined request set.
        const mixedRequests = _.flatMap(shortRequests, (short, i) => [short, longRequests[i]]);
        const sendBatches = metrics.batchAndSendRequests(mixedRequests);

        // sendBatches next puts a "fetchMetrics" action into the store.
        assert.deepEqual(sendBatches.next().value, put(metrics.fetchMetrics()));

        // Next, sendBatches dispatches a "all" effect with a "call" for each
        // batch; there should be two batches in total, one containing the
        // short requests and one containing the long requests. The order
        // of requests in each batch is maintained.
        const allEffect = sendBatches.next().value as AllEffect;
        assert.isArray(allEffect.ALL);
        assert.deepEqual(allEffect.ALL, [
          call(metrics.sendRequestBatch, shortRequests),
          call(metrics.sendRequestBatch, longRequests),
        ]);

        // After completion, puts "fetchMetricsComplete" to store.
        assert.deepEqual(sendBatches.next().value, put(metrics.fetchMetricsComplete()));
        assert.isTrue(sendBatches.next().done);
      });
Пример #6
0
export function assertPin(pin: IPin, type?: PIN_TYPE) {
  assert.isObject(pin);
  assertNotEmptyString(pin.type);

  if (type) {
    assert.strictEqual(pin.type, type);
  }

  assertNotEmptyString(pin.name);
  assertCoords(pin.coords);

  if (pin.type === PIN_TYPE.platform) {
    assert.isString(pin.id);
    assertNotEmptyString(pin.platform_nr);
  } else {
    assertNotEmptyString(pin.id);
    assert.isUndefined(pin.platform_nr);
  }

  if (pin.type === PIN_TYPE.stop) {
    assert.isArray(pin.connections);
    if (pin.name !== "Ebertplatz") {
      assert.isNotEmpty(pin.connections);
    }
    pin.connections!.forEach(assertConnection);
  } else {
    assert.isUndefined(pin.connections);
  }

  if (pin.type === PIN_TYPE.parkandride) {
    assertNotEmptyString(pin.info);
  } else {
    assert.isUndefined(pin.info);
  }
}
Пример #7
0
 it('should have default values', () => {
   assert.equal(group.name, '');
   assert.equal(group.path, '');
   assert.isArray(group.items);
   assert.deepEqual(group.items, []);
   assert.equal(group.groupBy, undefined);
   assert.equal(group.orderGroupBy, undefined);
 });
  @test('updating product tags persists successfully')
  public async tagUpdatesPersist() {
    await updateProduct(this.productId, { tags: ['foo', 'bar'] });
    let prod = await getProduct(this.productId);

    assert.isArray(prod.tags, 'tags property is an array');
    assert.equal(prod.tags.length, 2, 'tags has length 2');
  }
Пример #9
0
 it('should create a stack trace', () => {
   assert.isArray(subject.stackTrace);
   assert.ok(subject.stackTrace[0].fileName);
   assert.ok(subject.stackTrace[0].lineNumber);
   assert.ok(subject.stackTrace[0].columnNumber);
   assert.ok(subject.stackTrace[0].methodName);
   assert.ok(subject.stackTrace[0].className);
 });
Пример #10
0
export function assertTrip(trip: ITrip) {
  assertStopLocation(trip.departure!);
  assertStopLocation(trip.arrival!);
  assert.isNumber(trip.duration);
  assert.isNumber(trip.interchanges);

  assert.isArray(trip.nodes);
  trip.nodes.forEach(assertNode);
}