test(DatePipe): fixes

This commit is contained in:
Victor Berchet 2016-06-17 15:34:39 -07:00
parent 76a418760e
commit 40f8a45b95
3 changed files with 11 additions and 11 deletions

View File

@ -20,7 +20,8 @@ export function main() {
// TODO(mlaval): enable tests when Intl API is no longer used, see // TODO(mlaval): enable tests when Intl API is no longer used, see
// https://github.com/angular/angular/issues/3333 // https://github.com/angular/angular/issues/3333
if (browserDetection.supportsIntlApi) { // Have to restrict to Chrome as IE uses a different formatting
if (browserDetection.supportsIntlApi && browserDetection.isChromeDesktop) {
describe('supports', () => { describe('supports', () => {
it('should support date', () => { expect(() => pipe.transform(date)).not.toThrow(); }); it('should support date', () => { expect(() => pipe.transform(date)).not.toThrow(); });
it('should support int', () => { expect(() => pipe.transform(123456789)).not.toThrow(); }); it('should support int', () => { expect(() => pipe.transform(123456789)).not.toThrow(); });
@ -56,13 +57,13 @@ export function main() {
expect(pipe.transform(date, 'MMM d')).toEqual('Jun 15'); expect(pipe.transform(date, 'MMM d')).toEqual('Jun 15');
expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015'); expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015');
expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015'); expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
expect(pipe.transform(date, 'yMEd')).toEqual('Mon, 6/15/2015'); expect(pipe.transform(date, 'yMEd')).toEqual('20156Mon15');
expect(pipe.transform(date, 'MEd')).toEqual('Mon, 6/15'); expect(pipe.transform(date, 'MEd')).toEqual('6Mon15');
expect(pipe.transform(date, 'MMMd')).toEqual('Jun 15'); expect(pipe.transform(date, 'MMMd')).toEqual('Jun15');
expect(pipe.transform(date, 'yMMMMEEEEd')).toEqual('Monday, June 15, 2015'); expect(pipe.transform(date, 'yMMMMEEEEd')).toEqual('Monday, June 15, 2015');
expect(pipe.transform(date, 'jms')).toEqual('9:43:11 PM'); expect(pipe.transform(date, 'jms')).toEqual('9:43:11 PM');
expect(pipe.transform(date, 'ms')).toEqual('43:11'); expect(pipe.transform(date, 'ms')).toEqual('4311');
expect(pipe.transform(date, 'jm')).toEqual('9:43'); expect(pipe.transform(date, 'jm')).toEqual('9:43 PM');
}); });
it('should format with pattern aliases', () => { it('should format with pattern aliases', () => {

View File

@ -7,7 +7,8 @@ export function main() {
describe('Number pipes', () => { describe('Number pipes', () => {
// TODO(mlaval): enable tests when Intl API is no longer used, see // TODO(mlaval): enable tests when Intl API is no longer used, see
// https://github.com/angular/angular/issues/3333 // https://github.com/angular/angular/issues/3333
if (browserDetection.supportsIntlApi) { // Have to restrict to Chrome as IE uses a different formatting
if (browserDetection.supportsIntlApi && browserDetection.isChromeDesktop) {
describe('DecimalPipe', () => { describe('DecimalPipe', () => {
var pipe: DecimalPipe; var pipe: DecimalPipe;

View File

@ -1,6 +1,6 @@
import {getDOM} from '../src/dom/dom_adapter'; import {getDOM} from '../src/dom/dom_adapter';
import {ListWrapper} from '../src/facade/collection'; import {ListWrapper} from '../src/facade/collection';
import {RegExp, RegExpWrapper, StringWrapper, isPresent, isString, global} from '../src/facade/lang'; import {RegExp, RegExpWrapper, StringWrapper, global, isPresent, isString} from '../src/facade/lang';
export class BrowserDetection { export class BrowserDetection {
private _overrideUa: string; private _overrideUa: string;
@ -40,9 +40,7 @@ export class BrowserDetection {
// The Intl API is only properly supported in recent Chrome and Opera. // The Intl API is only properly supported in recent Chrome and Opera.
// Note: Edge is disguised as Chrome 42, so checking the "Edge" part is needed, // Note: Edge is disguised as Chrome 42, so checking the "Edge" part is needed,
// see https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx // see https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
get supportsIntlApi(): boolean { get supportsIntlApi(): boolean { return !!(<any>global).Intl; }
return !!(<any>global).Intl;
}
get isChromeDesktop(): boolean { get isChromeDesktop(): boolean {
return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 && return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&