[Angular Unit Testing] Testing Pipe

import { Pipe, PipeTransform } from ‘@angular/core‘;

@Pipe({
  name: ‘filesize‘
})
export class FileSizePipe implements PipeTransform {
  transform(size: number, extension: string = ‘MB‘) {
    return (size / (1024 * 1024)).toFixed(2) + extension;
  }
}
import { FileSizePipe } from ‘./file-size.pipe‘;

describe(‘FileSizePipe‘, () => {

  describe(‘Isolate FileSizePipe test‘, () => {

    const pipe = new FileSizePipe();

    it(‘should convert bytes to megabytes‘, () => {
      expect(pipe.transform(123456789)).toBe(‘117.74MB‘);
      expect(pipe.transform(987654321)).toBe(‘941.90MB‘);
    });

    it(‘should use the default extension when not supplied‘, () => {
      expect(pipe.transform(123456789)).toBe(‘117.74MB‘);
      expect(pipe.transform(987654321)).toBe(‘941.90MB‘);
    });

    it(‘should override the extension when supplied‘, () => {
      expect(pipe.transform(123456789, ‘myExt‘)).toBe(‘117.74myExt‘);
      expect(pipe.transform(987654321, ‘anotherExt‘)).toBe(‘941.90anotherExt‘);
    });
  });

});
时间: 2024-11-12 03:47:19

[Angular Unit Testing] Testing Pipe的相关文章

[Angular + Unit Testing] Mock HTTP Requests made with Angular’s HttpClient in Unit Tests

In a proper unit test we want to isolate external dependencies as much as possible to guarantee a reliable test outcome. Http calls represent such external dependencies. Therefore, when testing our Angular components or services that rely on data ret

[Angular 8 Unit Testing] Testing a component

Setting up a Presentational Component: import {Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation} from '@angular/core'; import {Course} from '../model/course'; import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; imp

[Angular + Unit] AngularJS Unit testing using Karma

http://social.technet.microsoft.com/wiki/contents/articles/32300.angularjs-unit-testing-using-karma-part-1.aspx Testing Controller Testing $httpbackend Testing Service

[Unit Testing] Angular Unit Testing, ui-router, httpbackend and spy

// backend test beforeEach(inject(function (_$compile_, _$httpBackend_, _$rootScope_, _$state_, _AnnouncementsService_, _CONFIG_) { compile = _$compile_; $httpBackend = _$httpBackend_; $scope = _$rootScope_.$new(); AnnouncementsService = _Announcemen

Run Unit API Testing Which Was Distributed To Multiple Test Agents

Recently I am blocked by a very weird issue, from the VS installed machine, I can run performance testing which was distributed to multiple test agents successfully, but if try to run API testing, it is always failed, I have tried run in VS and also

Android application testing with the Android test framework

目录(?)[-] Android automated testing 1 How to test Android applications Tip 2 Unit tests vs functional tests 3 JUnit 3 4 Running tests on a server without display Test hooks into the Android framework 1 Instrumentation 2 How the Android system executes

Android Testing Point

The test application demonstrates these key points: An Android test is itself an Android application that is linked to the application under test by entries in its AndroidManifest.xml file. //一个Android的测试本身是由被测项目在AndroidManifest.xml文件链接到应用程序的Android应

<Learning Selenium Testing Tools with Python>

书在这里 Selenium is a set of tools for automating browsers Selenium IDE: This is a Firefox add-in used to record and play back the Selenium scripts with Firefox. Selenium WebDriver: This is a programming interface for developing advanced Selenium script

SD6503 Testing and Secure Coding

Final Project_ SD6503 Testing and Secure Coding_T2_2019 Page 1 of 4BACHELOR OF INFORMATION TECHNOLOGYSD6503 Testing and Secure CodingFinal ProjectTrimester 2, 2019Secure Web Project Development and Testing — Group ProjectDue date and timeDue: Tuesday