Skip to content

Commit

Permalink
test: improve ngx meta core module unit tests (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 authored Sep 24, 2024
1 parent 2f6b805 commit 5befe1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
7 changes: 2 additions & 5 deletions projects/ngx-meta/src/core/src/metadata-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
* Defines the metadata values to use for a page. Broadly speaking, it's just
* a JSON object
*
* @remarks
*
* You can ensure its proper shape by using `XMetadata` types where `X` is the
* metadata module. Or {@link GlobalMetadata} for metadata values shared amongst
* one or more modules.
* See the {@link https://ngx-meta.dev/guides/metadata-values-json/ | metadata values JSON}
* guide for more information about typing metadata values with more strict types
*
* @public
*/
Expand Down
23 changes: 20 additions & 3 deletions projects/ngx-meta/src/core/src/ngx-meta-core.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { TestBed } from '@angular/core/testing'
import { NgxMetaCoreModule } from './ngx-meta-core.module'
import { DEFAULTS_TOKEN } from './defaults-token'
import { ModuleWithProviders } from '@angular/core'
import { GlobalMetadata } from '@davidlj95/ngx-meta/core'

describe('Core module', () => {
it('provides no defaults by default', () => {
TestBed.configureTestingModule({ imports: [NgxMetaCoreModule.forRoot()] })
makeSut(NgxMetaCoreModule.forRoot())
expect(TestBed.inject(DEFAULTS_TOKEN, null, { optional: true })).toBeNull()
})

it('provides no defaults if not specified', () => {
TestBed.configureTestingModule({ imports: [NgxMetaCoreModule.forRoot({})] })
it('provides no defaults if options object is empty', () => {
makeSut(NgxMetaCoreModule.forRoot({}))
expect(TestBed.inject(DEFAULTS_TOKEN, null, { optional: true })).toBeNull()
})

it('provides defaults if specified as options object', () => {
const defaults: GlobalMetadata = { title: 'Hello World!' }
makeSut(NgxMetaCoreModule.forRoot({ defaults }))

expect(TestBed.inject(DEFAULTS_TOKEN, null, { optional: true })).toEqual(
defaults,
)
})
})

const makeSut = (
moduleWithProviders: ModuleWithProviders<NgxMetaCoreModule>,
) => {
TestBed.configureTestingModule({ imports: [moduleWithProviders] })
}

0 comments on commit 5befe1e

Please sign in to comment.