codeceptjs / codeceptjs/CodeceptJS

Inconsistent assert behavior for text

Abierto
#5,278 2 comentarios 1 reacción 0 asignados Ver en GitHub
stale
Lenguaje dominante
JavaScript
Estrellas
4.2k
Forks
757
Merge medio
2 d 9 h
PR fusionados (30 d)
16

Descripción

Hello!

While experimenting with codecept I noticed inconsistent behaviors between the testing methods.

Here are two tests:
- The first contains spans that have numbers in them. The asserts are generally consistent (they add spaces to each span) except grabTextFrom, which adds \n.
- The second is much more problematic. In this one, the HTML also contains spans, but with bootstrap styles on the spans. We can see that:
- I.see adds spaces
- I.waitForText does not
- nor does I.grabTextFrom
- BUT when we add .at(1) to the locator, it changes the behavior of waitForText().

The way the text is asserted changes depending on:
- the CSS of the page
- the assertion method used
- the selector
- the whitespaces in the HTML

```ts
import { writeFileSync } from "node:fs";
import { resolve } from "node:path";

Feature("Spans");

Scenario("text line returns", async ({ I }) => {
const file = `${resolve(process.cwd(), "examples", "returns.html")}`;
writeFileSync(file, `


1
2
3

`);
I.amOnPage(`file://${file}`);

const appLocator = locate("#app");

I.see("1 2 3", appLocator);
I.waitForText("1 2 3", 1, appLocator);

const text = await I.grabTextFrom(appLocator);
I.expect(text).toEqual("\n 1\n 2\n 3\n ");

I.see("1 2 3", appLocator.at(1));
I.waitForText("1 2 3", 1, appLocator.at(1));

const text2 = await I.grabTextFrom(appLocator.at(1));
I.expect(text2).toEqual("\n 1\n 2\n 3\n ");
});

Scenario("test boostrap styles", async ({ I }) => {
const file = `${resolve(process.cwd(), "examples", "bootstrap.html")}`;
writeFileSync(file, `

0.88678

`);
I.amOnPage(`file://${file}`);

const appLocator = locate("#app");

I.see("0 . 8 8 6 7 8", appLocator);
I.waitForText("0.88678", 1, appLocator);

const text = await I.grabTextFrom(appLocator);
I.expect(text).toEqual("0.88678");

I.see("0 . 8 8 6 7 8", appLocator.at(1));
// IDK what it expects... it just does not work the same with .at(1)!!!!
// I.waitForText("0.88678", 1, appLocator.at(1));

const text2 = await I.grabTextFrom(appLocator.at(1));
I.expect(text2).toEqual("0.88678");
});

```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.