mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
10 changed files with 111 additions and 22 deletions
@ -0,0 +1,42 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { TempService, TempServiceFactory } from './temp.service'; |
|||
|
|||
describe('TempService', () => { |
|||
it('should instantiate from factory', () => { |
|||
const tempService = TempServiceFactory(); |
|||
|
|||
expect(tempService).toBeDefined(); |
|||
}); |
|||
|
|||
it('should instantiate', () => { |
|||
const tempService = new TempService(); |
|||
|
|||
expect(tempService).toBeDefined(); |
|||
}); |
|||
|
|||
it('should return null when nothing is stored', () => { |
|||
const tempService = new TempService(); |
|||
|
|||
const temp = tempService.fetch(); |
|||
|
|||
expect(temp).toBeNull(); |
|||
}); |
|||
|
|||
it('should return value once when something is stored', () => { |
|||
const tempService = new TempService(); |
|||
|
|||
tempService.put('Hello'); |
|||
|
|||
const temp1 = tempService.fetch(); |
|||
const temp2 = tempService.fetch(); |
|||
|
|||
expect(temp1).toBe('Hello'); |
|||
expect(temp2).toBeNull(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,29 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { Injectable } from '@angular/core'; |
|||
|
|||
export const TempServiceFactory = () => { |
|||
return new TempService(); |
|||
}; |
|||
|
|||
@Injectable() |
|||
export class TempService { |
|||
private value: any = null; |
|||
|
|||
public put(value: any) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public fetch() { |
|||
const result = this.value; |
|||
|
|||
this.value = null; |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue