Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jules Sagot--Gentil
Flux articles console
Commits
b0044a58
Verified
Commit
b0044a58
authored
Feb 13, 2022
by
Jules Sagot--Gentil
Browse files
test(article): classe Writable utilitaire pour récupérer la sortie
parent
61c6787c
Pipeline
#469855145
passed with stage
in 55 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
test/writable.spec.ts
0 → 100644
View file @
b0044a58
import
{
WritableGetSortie
}
from
'
./writable
'
;
describe
(
'
La classe WritableGetSortie
'
,
()
=>
{
const
writable
=
new
WritableGetSortie
();
beforeEach
(()
=>
writable
.
reset
());
it
(
'
Doit pouvoir renvoyer son entrée
'
,
()
=>
{
const
message
=
'
Récupération des données
'
;
writable
.
write
(
message
);
expect
(
writable
.
getSortie
()).
toBe
(
message
);
})
it
(
'
Doit pouvoir renvoyer la somme de plusieurs entrées
'
,
()
=>
{
const
messageA
=
'
Récupération des données
'
;
const
messageB
=
'
\n
Ceci est un second message
'
;
writable
.
write
(
messageA
);
writable
.
write
(
messageB
);
expect
(
writable
.
getSortie
()).
toBe
(
messageA
+
messageB
);
})
})
test/writable.ts
0 → 100644
View file @
b0044a58
import
{
Writable
}
from
'
stream
'
;
/**
* @description Classe utilitaire permettant de récupérer ce qui a été
* écrit sous forme d'une chaîne de caractères à l'aide de la méthode
* getSortie
*/
export
class
WritableGetSortie
extends
Writable
{
private
sortie
:
string
=
''
;
public
_write
(
chunk
:
any
,
callback
?:
(
error
:
Error
|
null
|
undefined
)
=>
void
):
void
;
public
_write
(
chunk
:
any
,
encoding
:
BufferEncoding
,
callback
?:
(
error
:
Error
|
null
|
undefined
)
=>
void
):
void
;
public
_write
(...
args
:
any
[]):
void
{
this
.
sortie
+=
args
[
0
].
toString
();
if
(
args
.
length
==
2
&&
args
[
1
])
{
args
[
1
]();
}
if
(
args
.
length
==
3
&&
args
[
2
])
{
args
[
2
]();
}
}
public
getSortie
()
{
return
this
.
sortie
;
}
public
reset
()
{
this
.
sortie
=
''
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment