Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
RXJS from() doesn't execute within concatMap()

I am trying to run a test with Jasmine to click a button which copies a value to the clipboard. I'm then trying to read the value that was saved in the clipboard.

I am not sure what I am doing wrong here, but the output that I am getting in the console is this:

timer 1

What I am expecting to see in the console is this:

timer 1
read
timer 2

The Jasmine code that I am using looks like this:

  it('should copy input value', () => {
    const click = component.clickButton('buttonElRef');
    click.subscribe(value => {
      console.log('v', value);
    });
  });

The Angular test component looks like this:

class CopyToClipboardTest {
  clickButton(which: 'buttonObjRef' | 'buttonElRef'): Observable<string> {
    this[which].nativeElement.click();
    return timer(100).pipe(
      tap(() => console.log('timer 1')),
      concatMap(() => this.getClipboard()),
      tap(() => console.log('timer 2')),
    );
  }

  getClipboard(): Observable<string> {
    return from(navigator.clipboard.readText()).pipe(tap(() => console.log('read')));
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So, when using the clipboard you need to give the window focus before executing clipboard events.

This fixes the issue (it doesn't seem to work on auto reload though):

beforeAll(() => window.focus());
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda