Skip to content

Inconsistent treatment of strings in different object types #2545

@plocket

Description

@plocket

👓 What did you see?

Summary: A multiline string (with \n) in a data table seems to have actual new lines while the same multiline string gets stringified when it is in Step text and just has the literal text \n. I would find the first behavior more useful. The second behavior doesn't work for my purposes. I'd like to be able to use both kinds of formats. I have replicated this in a sandbox with console logs.

Code in steps.js

const { When } = require("@cucumber/cucumber");

When("someone writes", function (dataTable) {
  console.log(dataTable.raw()[0][1]);
});

When("someone says {string}", function (phrase) {
  console.log(phrase);
});

Code in greeting.feature

Feature: Strings

	Scenario: Compare string behavior
		Then someone writes
		    | data | line1\nline2 |
		When someone says "line1\nline2"

The someone writes step console logs this:

line1
line2

The someone says step console logs this:

line1\nline2

I'm using cucumberjs to test filling out forms. When I fill in textarea elements, a data table lets me enter new lines correctly. When I use a regular step, the text area doesn't show multiple lines but instead the literal text line1\nline2 (which includes the \ and the n). I have not yet been able to find a way to change the literal \n into an actual new line in a textarea. Changing my puppeteer code might do it, but my tests need to type the text in letter by letter instead of just setting the value of the textarea node.

✅ What did you expect to see?

I would like to get an actual new line in both cases so that the textarea field gets the right value:

line1
line2

📦 Which tool/library version are you using?

node v18.17.0
@cucumber/cucumber v9.3.0

🔬 How could we reproduce it?

Here is the codesandbox replication of the behavior.

Code in steps.js

const { When } = require("@cucumber/cucumber");

When("someone writes", function (dataTable) {
  console.log(dataTable.raw()[0][1]);
});

When("someone says {string}", function (phrase) {
  console.log(phrase);
});

Code in greeting.feature

Feature: Strings

	Scenario: Compare string behavior
		Then someone writes
		    | data | line1\nline2 |
		When someone says "line1\nline2"

Run the tests.

📚 Any additional context?

Thanks for the work you folks do here. This has been an amazing tool for me. I wish I could do more to support the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ❓ questionConsider using support forums: https://cucumber.io/tools/cucumber-open/support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions