forked from knockout/knockout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alias ko.utils.unwrapObservable as ko.unwrap, and improve spec coverage
- Loading branch information
1 parent
bb46e03
commit eeda8c0
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe('unwrapObservable', function() { | ||
it('Should return the underlying value of observables', function() { | ||
var someObject = { abc: 123 }, | ||
observablePrimitiveValue = ko.observable(123), | ||
observableObjectValue = ko.observable(someObject), | ||
observableNullValue = ko.observable(null), | ||
observableUndefinedValue = ko.observable(undefined), | ||
computedValue = ko.computed(function() { return observablePrimitiveValue() + 1; }); | ||
|
||
expect(ko.utils.unwrapObservable(observablePrimitiveValue)).toBe(123); | ||
expect(ko.utils.unwrapObservable(observableObjectValue)).toBe(someObject); | ||
expect(ko.utils.unwrapObservable(observableNullValue)).toBe(null); | ||
expect(ko.utils.unwrapObservable(observableUndefinedValue)).toBe(undefined); | ||
expect(ko.utils.unwrapObservable(computedValue)).toBe(124); | ||
}); | ||
|
||
it('Should return the supplied value for non-observables', function() { | ||
var someObject = { abc: 123 }; | ||
|
||
expect(ko.utils.unwrapObservable(123)).toBe(123); | ||
expect(ko.utils.unwrapObservable(someObject)).toBe(someObject); | ||
expect(ko.utils.unwrapObservable(null)).toBe(null); | ||
expect(ko.utils.unwrapObservable(undefined)).toBe(undefined); | ||
}); | ||
|
||
it('Should be aliased as ko.unwrap', function() { | ||
expect(ko.unwrap).toBe(ko.utils.unwrapObservable); | ||
expect(ko.unwrap(ko.observable('some value'))).toBe('some value'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters