The data-setting variant of .data takes only two arguments, a key and a value (and the data-getting variant only takes one argument). Remove your first argument to .data.
$("<div>").data('test','test').append('test').appendTo('body');
Note that jQuery's data doesn't set data- attributes; it stores values in an internal lookup table accessible with data-getting calls to .data. If you really need to set a data- attribute (e.g., for compatibility with other, non-jQuery code that expects one), you can set it explicitly with .attr:
$("<div>").attr('data-test','test').append('test').appendTo('body');
Note that the .data variant can store arbitrary values (because it uses an internal dictionary), while the .attr solution can only store strings (since it uses attribute values).
$.datainstead of.data$('<div />', {'data-test' : 'test', text : 'test'}).appendTo('body')