projects/angular/testing/src/utilities/fake-file-list.ts
A class that implements the FileList
interface.
This class facilitates easy creation of FileList
mocks, for UTs.
FileList
Properties |
|
Methods |
Accessors |
constructor(files: File[])
|
||||||||
Creates a
Parameters :
|
Public files |
Type : File[]
|
Default value : []
|
A list of files.
|
add | ||||||||
add(...files: File[])
|
||||||||
Add files to the collection.
Parameters :
Returns :
void
|
item | ||||||||
item(idx: number)
|
||||||||
Retrieve an item at the specified index.
Parameters :
Returns :
File
The file at the requested |
()
|
Returns :
IterableIterator<File>
|
[index: number]:
|
length |
getlength()
|
The total file count. |
export class FakeFileList implements FileList {
[index: number]: File;
/**
* The total file count.
*
*/
get length() {
return this.files.length;
}
/**
* Creates a `mock` for `FileList` in order to easily test file centric scenarios with `input`s.
*
* @param [files=[]] A list of files.
* @returns The mocked `FileList` instance.
*/
constructor(public files: File[] = []) {
files.forEach((file, idx) => {
this[idx] = file;
});
}
[Symbol.iterator](): IterableIterator<File> {
return this.files[Symbol.iterator]();
}
/**
* Retrieve an item at the specified index.
*
* @param idx The accesed index.
* @returns The file at the requested `idx`.
*/
item(idx: number): File {
return this[idx];
}
/**
* Add files to the collection.
*
* @param files The files that will be added to the collection.
*/
add(...files: File[]): void {
files.forEach(file => {
this[this.files.length] = file;
this.files.push(file);
});
}
}