Skip to content

Commit

Permalink
fixup! feat(common): add injection token for default date pipe format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasweiss committed Sep 5, 2022
1 parent 9590ddc commit e6fe1ae
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/common/test/pipes/date_pipe_spec.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DatePipe} from '@angular/common';
import {DATE_PIPE_DEFAULT_FORMAT, DatePipe} from '@angular/common';
import localeEn from '@angular/common/locales/en';
import localeEnExtra from '@angular/common/locales/extra/en';
import {Component, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
Expand Down Expand Up @@ -72,9 +72,31 @@ import {TestBed} from '@angular/core/testing';
});

describe('transform', () => {
it('should use "mediumDate" as the default format',
it('should use "mediumDate" as the default format if no default format is provided',
() => expect(pipe.transform('2017-01-11T10:14:39+0000')).toEqual('Jan 11, 2017'));

it('should give precedence to the passed in format over the default one',
() => expect(pipe.transform('2017-01-11T10:14:39+0000', 'shortDate')).toEqual('1/11/17'));

it('should take the default format into account when no format is passed in', () => {
@Component({
selector: 'test-component',
imports: [DatePipe],
template: '{{ value | date }}',
standalone: true,
providers: [{provide: DATE_PIPE_DEFAULT_FORMAT, useValue: 'shortDate'}]
})
class TestComponent {
value = '2017-01-11T10:14:39+0000';
}

const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

const content = fixture.nativeElement.textContent;
expect(content).toBe('1/11/17');
});

it('should return first week if some dates fall in previous year but belong to next year according to ISO 8601 format',
() => {
expect(pipe.transform('2019-12-28T00:00:00', 'w')).toEqual('52');
Expand Down

0 comments on commit e6fe1ae

Please sign in to comment.