resultutil_test.js 990 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2012 The Closure Library Authors. All Rights Reserved.
  2. // Use of this source code is governed by the Apache License, Version 2.0.
  3. goog.provide('goog.resultTest');
  4. goog.setTestOnly('goog.resultTest');
  5. goog.require('goog.result');
  6. goog.require('goog.testing.jsunit');
  7. function testSuccessfulResult() {
  8. var value = 'some-value';
  9. var result = goog.result.successfulResult(value);
  10. assertEquals(goog.result.Result.State.SUCCESS, result.getState());
  11. assertEquals(value, result.getValue());
  12. }
  13. function testFailedResult() {
  14. var error = new Error('something-failed');
  15. var result = goog.result.failedResult(error);
  16. assertEquals(goog.result.Result.State.ERROR, result.getState());
  17. assertEquals(error, result.getError());
  18. }
  19. function testCanceledResult() {
  20. var result = goog.result.canceledResult();
  21. assertEquals(goog.result.Result.State.ERROR, result.getState());
  22. var error = result.getError();
  23. assertTrue(error instanceof goog.result.Result.CancelError);
  24. }